【问题标题】:Where is the score function in scikit-learn classifiers located?scikit-learn 分类器中的得分函数在哪里?
【发布时间】:2016-02-17 13:18:57
【问题描述】:

scikit-learn 中运行交叉验证时,所有分类器都会有一个工厂函数score(),我可以轻松检查分类器的准确性,例如来自http://scikit-learn.org/stable/modules/cross_validation.html

>>> import numpy as np
>>> from sklearn import cross_validation
>>> from sklearn import datasets
>>> from sklearn import svm

>>> iris = datasets.load_iris()
>>> iris.data.shape, iris.target.shape
((150, 4), (150,))
>>> X_train, X_test, y_train, y_test = cross_validation.train_test_split(
...     iris.data, iris.target, test_size=0.4, random_state=0)

>>> X_train.shape, y_train.shape
((90, 4), (90,))
>>> X_test.shape, y_test.shape
((60, 4), (60,))

>>> clf = svm.SVC(kernel='linear', C=1).fit(X_train, y_train)
>>> clf.score(X_test, y_test)                           
0.96...

在挖掘scikit-learn 的github repo 之后,我仍然无法弄清楚clf.score() 函数的函数在哪里。

有此链接,但不包含score()https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/svm/classes.py

sklearn 分类器的 score() 函数位于何处?

我可以implement my own score function easily,但目的是构建我的库,使其与sklearn 分类器保持一致,不是想出我自己的评分函数 =)

【问题讨论】:

    标签: python function machine-learning scikit-learn cross-validation


    【解决方案1】:

    scikit-learn 分类器的默认score() 方法是准确度分数,为defined in the ClassifierMixin class。这个 mixin 是 scikit-learn 的大多数(全部?)内置分类器的父类。

    如果您正在编写自己的分类器,我建议您也继承此 mixin 和 BaseEstimator,以便您自动获得模型的评分和其他功能。

    【讨论】:

      猜你喜欢
      • 2016-04-22
      • 2016-06-18
      • 2016-04-14
      • 2015-05-09
      • 1970-01-01
      • 2014-10-24
      • 2020-02-11
      • 2019-04-16
      • 2020-02-14
      相关资源
      最近更新 更多