[英]test and train CSV file python
how to simply test and train data from CSV file in python pycharm如何简单地测试和训练 python pycharm 文件中的 CSV 文件中的数据
you check data from file " https://drive.google.com/file/d/1pvcuGk2nRTsYcd-l-_yNBzvvRj2qW5rF/view " file name is " Papers data.csv "您从文件“ https://drive.google.com/file/d/1pvcuGk2nRTsYcd-l-_yNBzvvRj2qW5rF/view ”中检查数据文件名是“论文数据.csv”
This is simple a simple copy past code how below file replace by "Papers data.csv"这是一个简单的复制过去的代码,如何将下面的文件替换为“Papers data.csv”
import logging
logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO)
import os
import gensim
test_data_dir = os.path.join(gensim.__path__[0], 'test', 'test_data')
lee_train_file = os.path.join(test_data_dir, 'lee_background.cor')
lee_test_file = os.path.join(test_data_dir, 'lee.cor')
import smart_open
def read_corpus(fname, tokens_only=False):
with smart_open.open(fname, encoding="iso-8859-1") as f:
for i, line in enumerate(f):
tokens = gensim.utils.simple_preprocess(line)
if tokens_only:
yield tokens
else:
yield gensim.models.doc2vec.TaggedDocument(tokens, [i])
train_corpus = list(read_corpus(lee_train_file))
test_corpus = list(read_corpus(lee_test_file, tokens_only=True))
# Let's take a look at the training corpus
print(train_corpus[:2])
# And the testing corpus looks like this:
print(test_corpus[:2])
model = gensim.models.doc2vec.Doc2Vec(vector_size=50, min_count=2, epochs=40)
model.build_vocab(train_corpus)
model.train(train_corpus, total_examples=model.corpus_count, epochs=model.epochs)
vector = model.infer_vector(['only', 'you', 'can', 'prevent', 'forest', 'fires'])
print(vector)
Tensorflow provides library to read CSV dataset to train and test on model. Tensorflow 提供库来读取 CSV 数据集,以在 model 上进行训练和测试。 Such as tf.io.decode_csv
and tf.data.experimental.CsvDataset
.如tf.io.decode_csv
和tf.data.experimental.CsvDataset
。
Complete guideline on Loading CSV data is explained on Tensorflow documentation . Tensorflow 文档中解释了有关加载 CSV 数据的完整指南。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.