预测结果从数据帧保存到CSV

时间:2020-05-21 00:07:35

标签: python-3.x pandas csv text-classification sklearn-pandas

我正在尝试找到2个以上预测数据帧结果的组合精度, 在对结果进行预测之后,将结果保存到csv中并获得最终的合并准确性,所有保存的结果都将导入并合并

但是在计算过程中,它并没有达到预期的效果,并且随着结果的出现而改变,结果保存到csv中的结果被更改了。我们还有另一种将结果保存到csv中的方法,因此,保留了结果的原始形式

test_result is test data having 
test_result['text'] and test_result['labels]

train_result is train data having 
train_result['text'] and t_result['sentiment]

time classifier = grid_svm.fit(train_result['text'], train_result['sentiment']) 
predicted= classifier.predict(test_result['lemma_text'])
print(classification_report(test_result['labels'], predicted)) 

预测的分类报告如下

enter image description here

# below code is used to save result to csv 
test_result.to_csv('result/2_entertainment.csv')
# below code is used to import same result from csv  again
test_data_2 = pd.read_csv('result/2_entertainment.csv')
#But now strangely the classification report changes drastically.
# I'm not sure where the error is happening 
#it seems that while saving result the result has been swaped 
print(classification_report(test_data_2['sentiment'], test_data_2['labels']))

enter image description here

0 个答案:

没有答案