首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TypeError:__init__()获取了意外的关键字参数'scoring‘

TypeError:__init__()获取了意外的关键字参数'scoring‘
EN

Stack Overflow用户
提问于 2013-02-18 08:57:31
回答 2查看 5.7K关注 0票数 3

它是如何实现这个演示代码的(摘自此处:http://scikit-learn.org/dev/auto_examples/grid_search_digits.html)

当明显得分是一个参数(http://scikit-learn.org/dev/modules/generated/sklearn.grid_search.GridSearchCV.html#sklearn.grid_search.GridSearchCV)时,TypeError: __init__() got an unexpected keyword argument 'scoring'

代码语言:javascript
复制
from __future__ import print_function

from sklearn import datasets
from sklearn.cross_validation import train_test_split
from sklearn.grid_search import GridSearchCV  
from sklearn.metrics import classification_report
from sklearn.svm import SVC

print(__doc__)

# Loading the Digits dataset
digits = datasets.load_digits()

# To apply an classifier on this data, we need to flatten the image, to
# turn the data in a (samples, feature) matrix:
n_samples = len(digits.images)
X = digits.images.reshape((n_samples, -1))
y = digits.target

# Split the dataset in two equal parts
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.5, random_state=0)

# Set the parameters by cross-validation
tuned_parameters = [{'kernel': ['rbf'], 'gamma': [1e-3, 1e-4],
                 'C': [1, 10, 100, 1000]},
                {'kernel': ['linear'], 'C': [1, 10, 100, 1000]}]

scores = ['precision', 'recall']

for score in scores:
    print("# Tuning hyper-parameters for %s" % score)
    print()

    clf = GridSearchCV(SVC(C=1), tuned_parameters, scoring=score)
    clf.fit(X_train, y_train, cv=5)

    print("Best parameters set found on development set:")
    print()
    print(clf.best_estimator_)
    print()
    print("Grid scores on development set:")
    print()
    for params, mean_score, scores in clf.grid_scores_:
        print("%0.3f (+/-%0.03f) for %r"
          % (mean_score, scores.std() / 2, params))
    print()

    print("Detailed classification report:")
    print()
    print("The model is trained on the full development set.")
    print("The scores are computed on the full evaluation set.")
    print()
    y_true, y_pred = y_test, clf.predict(X_test)
    print(classification_report(y_true, y_pred))
    print()

# Note the problem is too easy: the hyperparameter plateau is too flat and the
# output model is the same for precision and recall with ties in quality.
EN

回答 2

Stack Overflow用户

发布于 2013-02-18 09:11:29

参数scoring是0.14开发版本中的新参数,示例代码是针对该版本的。您安装的scikit可能是0.13或更低版本,没有评分参数。

票数 7
EN

Stack Overflow用户

发布于 2013-02-18 09:11:46

您是否正在运行开发版本?

例如,0.12中不支持该参数

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14928018

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档