简体   繁体   English

机器学习预测另一个值

[英]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.

相关问题 如何为我训练有素的机器学习 model 提供输入以预测 output? - How to give input to my trained machine learning model to predict the output? 使用机器学习预测产品交货日期时的问题 - Problem when using Machine learning to predict product delivery date 如何使用机器学习算法预测容错? - How to predict fault tolerance using Machine Learning Algorithm? 创建分类器并设置用于机器学习的训练数据后,无法预测该值。 显示一些错误 - Not able to predict the value after creating a classifier and setting up the training data for machine learning. Some error is showing 为什么 Keras model.predict 永远不会在我设置的这个简单的机器学习模型上执行? - Why does Keras model.predict never execute on this simple machine learning model I've setup? 有没有办法实现机器学习 model 可以预测给定数据集中出现次数最多的句子 - is there any way to implement a machine learning model that can predict most occured sentence in a given dataset Pandas - 如何使用相邻列的值预测另一列的值 - Pandas - How to predict values of a another column with values from neighboring columns 时间序列预测是否属于监督学习? 还是机器学习的另一类? - Does time series forecasting belong to supervised learning? or is it another category of machine learning? 预处理机器学习中的错误 - error on preprocessing machine learning 机器从sklearn学习 - machine learning from sklearn
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM