gpt4 book ai didi

python - scikit 学习决策树模型评估

转载 作者:太空宇宙 更新时间:2023-11-03 14:59:48 25 4
gpt4 key购买 nike

下面是相关的代码和文档,想知道默认的cross_val_score没有明确指定score,输出数组是指精度,AUC还是其他一些指标?

将 Python 2.7 与 miniconda 解释器结合使用。

http://scikit-learn.org/stable/modules/generated/sklearn.tree.DecisionTreeClassifier.html

>>> from sklearn.datasets import load_iris
>>> from sklearn.cross_validation import cross_val_score
>>> from sklearn.tree import DecisionTreeClassifier
>>> clf = DecisionTreeClassifier(random_state=0)
>>> iris = load_iris()
>>> cross_val_score(clf, iris.data, iris.target, cv=10)
...
...
array([ 1. , 0.93..., 0.86..., 0.93..., 0.93...,
0.93..., 0.93..., 1. , 0.93..., 1. ])

问候,林

最佳答案

来自user guide :

By default, the score computed at each CV iteration is the score method of the estimator. It is possible to change this by using the scoring parameter:

来自决策树分类器 documentation :

Returns the mean accuracy on the given test data and labels. In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.

不要对“平均准确度”感到困惑,这只是计算准确度的常规方法。点击链接到 source :

    from .metrics import accuracy_score
return accuracy_score(y, self.predict(X), sample_weight=sample_weight)

现在 source对于 metrics.accuracy_score

def accuracy_score(y_true, y_pred, normalize=True, sample_weight=None):
...
# Compute accuracy for each possible representation
y_type, y_true, y_pred = _check_targets(y_true, y_pred)
if y_type.startswith('multilabel'):
differing_labels = count_nonzero(y_true - y_pred, axis=1)
score = differing_labels == 0
else:
score = y_true == y_pred

return _weighted_sum(score, sample_weight, normalize)

如果你 still aren't convinced:

def _weighted_sum(sample_score, sample_weight, normalize=False):
if normalize:
return np.average(sample_score, weights=sample_weight)
elif sample_weight is not None:
return np.dot(sample_score, sample_weight)
else:
return sample_score.sum()

注意:对于 accuracy_score 规范化参数默认为 True,因此它只是返回 bool numpy 数组的 np.average,因此它很简单正确预测的平均数。

关于python - scikit 学习决策树模型评估,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39094267/

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