gpt4 book ai didi

python - 评估预测的准确性

转载 作者:行者123 更新时间:2023-11-30 09:01:41 24 4
gpt4 key购买 nike

我已经训练并测试了我的 KNN 分类器。我已经交叉验证了它,平均分数还不错。现在,我想预测一些真实数据的标签。但有没有办法查看预测的准确性呢?仅当准确度足够高时,我才想实际保存预测标签。我正在使用 Python 和 scikit-learn。

最佳答案

正如 @jonrsharpe 所说,predict_proba 应该做到这一点。

它提供了一个包含所有类别概率的数组。假设您有 3 个类别 [A、B、C]。 predict_proba 方法将返回[0.2,0.3,0.5]。所以这里你的准确度是

A=0.2
B=0.3
C=0.5

例如:

categories = [A, B, C]
X = # put your data
Y = # put your result

classifier.fit(X, Y)
prediction = classifier.predict_proba(X) # predict whatever you want here

for line in prediction:
# numpy.argmax return the index of the biggest value in the array
# max return the biggest value
print("The class is %s with proba : %f " % (categories[numpy.argmax(line)], max(line, key=float)))

重要:注意类别数组中的顺序。 Predict_proba 结果的内容根据类别按词法排序。在处理结果之前不要犹豫对类别进行排序

关于python - 评估预测的准确性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29603541/

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