f1、precision、accuracy 和 recall 都可以有相同的值吗?

Can the f1, precision, accuracy and recall all have the same values?

我一直在尝试使用 scikit-learn 实现支持向量机算法,在进行一些测量后,所有分数都提供相同的值。

x = df["Text"]
y = df["Mood"]

test_size = 5122

x_test = x[:-test_size]
y_test = y[:-test_size]

x_train = x[-test_size:]
y_train = y[-test_size:]

count_vect = CountVectorizer()
X_train_counts = count_vect.fit_transform(x_train)
tfidf_transformer = TfidfTransformer()
X_train_tfidf = tfidf_transformer.fit_transform(X_train_counts)
x_test = count_vect.transform(x_test).toarray()

SVM = svm.SVC(C=1.0, kernel='linear', degree=3, gamma='auto')
SVM.fit(X_train_tfidf, y_train)
predictions_SVM = SVM.predict(x_test)

print('Accuracy score is: ', accuracy_score(y_test, predictions_SVM))
print('F1 score is: ', f1_score(y_test, predictions_SVM, average='micro'))
print('Precission score is: ', precision_score(y_test, predictions_SVM, average ='micro'))
print('Recall score is: ', recall_score(y_test, predictions_SVM, average='micro'))

输出:

Accuracy score is:  0.9687622022647403
F1 score is:  0.9687622022647403
Precission score is:  0.9687622022647403
Recall score is:  0.9687622022647403

这是正常现象还是我哪里出错了?

查看这些分数的文档,当您使用 'micro'.

时,它们看起来应该都是一样的

他们都在计算你得到正确标签的次数。

查看示例:

https://scikit-learn.org/stable/modules/generated/sklearn.metrics.accuracy_score.html

https://scikit-learn.org/stable/modules/generated/sklearn.metrics.f1_score.html

https://scikit-learn.org/stable/modules/generated/sklearn.metrics.precision_score.html

https://scikit-learn.org/stable/modules/generated/sklearn.metrics.recall_score.html

事实上最后三个​​他们都举了同样的例子,当然得到了同样的分数。