简体   繁体   English

如何将 TensorFlow 训练数据导出到 CSV

[英]How to export TensorFlow training data to CSV

I'm running a SVM sentiment analysis project and I wanted to vectorize it using tf-idf.我正在运行一个 SVM 情绪分析项目,我想使用 tf-idf 对其进行矢量化。 the code snip for the tf-idf section is below: tf-idf 部分的代码片段如下:

X = table_tfidf

y = df['label']

random_state = 42

from sklearn.model_selection import train_test_split

X_train, X_test, y_train, y_text = train_test_split(X, y, test_size=0.2, random_state=random_state)

#dividing training data to train data and validation data

X_train_train, X_train_val, y_train_train, y_train_val = train_test_split(X_train, y_train, test_size = 0.2)

how do I export the X_train and the y_train only data into a.csv file?如何将仅 X_train 和 y_train 数据导出到 a.csv 文件中? I wanted to check if the data were properly split.我想检查数据是否正确拆分。 Thank you!谢谢!

This should do it:这应该这样做:

X_train.to_csv('X_train.csv')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM