我正在尝试进行情感分类,并使用了sklearn的SVM模型。我用标记的数据训练了模型,获得了89%的准确率。现在我想用这个模型来预测未标记数据的情感。我该怎么做?在对未标记数据进行分类后,如何查看它是被分类为正面还是负面?
我使用的是Python 3.7。以下是代码。
当我运行这段代码时,得到的输出是:
ConvergenceWarning: Liblinear failed to converge, increase the number of iterations. “the number of iterations.”, ConvergenceWarning) Accuracy : 0.8977272727272727 Precision : 0.8604651162790697 Recall : 0.925
ConvergenceWarning的含义是什么?
提前感谢!
回答:
ConvergenceWarning的含义是什么?
正如@已提到的,ConvergenceWarning意味着max_iter
已被触发,你可以在这里抑制警告:如何使用sklearn禁用ConvergenceWarning?
现在我想用这个模型来预测未标记数据的情感。我该怎么做?
你可以使用命令:pred_y = clf.predict(test_x)
来实现,唯一需要调整的是:pred_y
(这是你的自由选择),以及test_x
,这应该是你的新未见数据,它必须具有与你的数据test_x
和train_x
相同的特征数量。
在你的案例中,你正在做:
sentiment_data = list(zip(data['Articles'], data['Sentiment']))
train_x, train_y = zip(*sentiment_data[:350])
这里你的train_x
是列:data['Articles']
,所以如果你有新数据,你只需做:
new_ data = pd.read_csv("new_data.csv", header=0)new_y = clf.predict(new_data['Articles'])
如何查看它是被分类为正面还是负面?
你可以运行:pred_y
,结果中将会有1或0。通常0表示负面,但这取决于你的数据集设置。