gpt4 book ai didi

machine-learning - F1 micro 与 Accuracy 一样吗?

转载 作者:行者123 更新时间:2023-11-30 08:23:06 25 4
gpt4 key购买 nike

我在 scikit-learn 中尝试了许多使用 F1 micro 和 Accuracy 的示例,在所有示例中,我发现 F1 micro 与 Accuracy 相同。这总是正确的吗?

脚本

from sklearn import svm
from sklearn import metrics
from sklearn.cross_validation import train_test_split
from sklearn.datasets import load_iris
from sklearn.metrics import f1_score, accuracy_score

# prepare dataset
iris = load_iris()
X = iris.data[:, :2]
y = iris.target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)

# svm classification
clf = svm.SVC(kernel='rbf', gamma=0.7, C = 1.0).fit(X_train, y_train)
y_predicted = clf.predict(X_test)

# performance
print "Classification report for %s" % clf
print metrics.classification_report(y_test, y_predicted)

print("F1 micro: %1.4f\n" % f1_score(y_test, y_predicted, average='micro'))
print("F1 macro: %1.4f\n" % f1_score(y_test, y_predicted, average='macro'))
print("F1 weighted: %1.4f\n" % f1_score(y_test, y_predicted, average='weighted'))
print("Accuracy: %1.4f" % (accuracy_score(y_test, y_predicted)))

输出

Classification report for SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0,
decision_function_shape=None, degree=3, gamma=0.7, kernel='rbf',
max_iter=-1, probability=False, random_state=None, shrinking=True,
tol=0.001, verbose=False)
precision recall f1-score support

0 1.00 0.90 0.95 10
1 0.50 0.88 0.64 8
2 0.86 0.50 0.63 12

avg / total 0.81 0.73 0.74 30

F1 micro: 0.7333

F1 macro: 0.7384

F1 weighted: 0.7381

Accuracy: 0.7333

F1 micro = 准确性

最佳答案

在保证每个测试用例都准确分配到一个类的分类任务中,micro-F 相当于准确性。在多标签分类中就不会出现这种情况。

关于machine-learning - F1 micro 与 Accuracy 一样吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37358496/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com