gpt4 book ai didi

python - sklearn 中的预测评分(Python 机器学习)

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

我正在浏览以下 IPython Notebook,它分析了 Iris dataset

作者在笔记本中的某个时刻构建了以下模型:

enter image description here

此时我感到很困惑。最后一行发生了什么?根据我的了解,您应该根据模型创建一个预测,然后将该预测与 y_test 值进行比较。

我会做以下事情:

predictions = decision_tree_classifier.predict(X_test)
from sklearn.metrics import classification_report
print classification_report(y_test, predictions)

当作者根据 testing_inputstesting_classes 生成分数时,会发生什么情况?

最佳答案

来自docs :

score(X, y, sample_weight=None)

Returns the mean accuracy on the given test data and labels.

这正是它的作用。它在内部对 X_test 进行预测,生成 y_pred 并将其与 y_test 进行比较以计算准确性分数。

您所做的事情类似,但分两步。您首先进行预测,然后与 y_test 进行比较。此外,您还打印出精度、召回率和 f1 分数。

关于python - sklearn 中的预测评分(Python 机器学习),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44915004/

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