[英]Machine Learning Predict Another Values
I'm really new at ML.我真的是 ML 的新手。 I trained my dataset then I save it with pickle.我训练了我的数据集,然后用 pickle 保存它。 My trained dataset has text and value.我训练有素的数据集具有文本和价值。 I'm trying to get an estimate from my new dataset, which has only text.我正在尝试从我的新数据集中获得估计,该数据集中只有文本。
However, when I try to predict new values with my trained data, I'm getting an error, which says但是,当我尝试使用训练有素的数据预测新值时,我得到了一个错误,它说
ValueError: Number of features of the model must match the input. ValueError:model 的特征数量必须与输入匹配。 Model n_features is 17804 and input n_features is 24635 Model n_features 为 17804,输入 n_features 为 24635
You can check my code below.您可以在下面查看我的代码。 What I have to do at this point?在这一点上我必须做什么?
with open('trained.pickle', 'rb') as read_pickle:
loaded=pickle.load(read_pickle)
dataset2 = pandas.read_csv('/root/Desktop/predict.csv' , encoding='cp1252')
X2_train=dataset2['text']
train_tfIdf = vectorizer_tfidf.fit_transform(X2_train.values.astype('U'))
x = loaded.predict(train_tfIdf)
print(x)
fit_transform fits to the data and then transforms it, which you don't want to do while testing. fit_transform适合数据然后对其进行转换,这是您在测试时不想做的。 It is like retraining the tfidf.这就像重新训练 tfidf。 So, for the purpose of prediction, I would suggest using the transform method simply.因此,出于预测的目的,我建议简单地使用变换方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.