2
更新的问题: 我这样做,但我得到了同样的结果,既精度和召回是因为我使用average ='binary'?使用sklearn获得相同的精度和召回(K-NN)值
但是当我使用平均= '宏观' 我收到此错误信息:
测试定制审核 messageC:\ Python27 \ LIB \站点包\ sklearn \指标\ classification.py:976 : DeprecationWarning:从版本0.18开始,当使用平均精确度/召回率/ F-分数时,二进制输入将不是 。请 使用average ='binary'仅报告正面课堂表现。
“正级性能”,DeprecationWarning)
这是我更新的代码:
path = 'opinions.tsv'
data = pd.read_table(path,header=None,skiprows=1,names=['Sentiment','Review'])
X = data.Review
y = data.Sentiment
#Using CountVectorizer to convert text into tokens/features
vect = CountVectorizer(stop_words='english', ngram_range = (1,1), max_df = .80, min_df = 4)
X_train, X_test, y_train, y_test = train_test_split(X,y,random_state=1, test_size= 0.2)
#Using training data to transform text into counts of features for each message
vect.fit(X_train)
X_train_dtm = vect.transform(X_train)
X_test_dtm = vect.transform(X_test)
#Accuracy using KNN Model
KNN = KNeighborsClassifier(n_neighbors = 3)
KNN.fit(X_train_dtm, y_train)
y_pred = KNN.predict(X_test_dtm)
print('\nK Nearest Neighbors (NN = 3)')
#Naive Bayes Analysis
tokens_words = vect.get_feature_names()
print '\nAnalysis'
print'Accuracy Score: %f %%'% (metrics.accuracy_score(y_test,y_pred)*100)
print "Precision Score: %f%%" % precision_score(y_test,y_pred, average='binary')
print "Recall Score: %f%%" % recall_score(y_test,y_pred, average='binary')
通过使用上面的代码,我得到相同价值的准确率和召回
谢谢你回答我的问题,非常感谢。
谢谢回答,但我还是在计算精度和召回了一些问题,我得到的相同的值 你能看看我更新的问题吗?非常感谢 –
这是不是一个问题,你收到精度和召回指标相同的价值。这只是数据的一个特点。要添加,您收到的消息不是错误,它表示您的输入是二进制的,即。即无论是零还是一个,所以您应该使用'average ='binary''来计算精度和召回指标。 –