python – TypeError:__ init __()得到一个意外的关键字参数’scoring’
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了python – TypeError:__ init __()得到一个意外的关键字参数’scoring’,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2146字,纯文字阅读大概需要4分钟。
内容图文
![python – TypeError:__ init __()得到一个意外的关键字参数’scoring’](/upload/InfoBanner/zyjiaocheng/749/e26b2f326a354cfb8e7a9cfc06342e27.jpg)
这个演示代码怎么可能(取自这里:http://scikit-learn.org/dev/auto_examples/grid_search_digits.html)
TypeError:__ init __()得到一个意外的关键字参数’scoring’,当obviuodly scoring是一个参数(http://scikit-learn.org/dev/modules/generated/sklearn.grid_search.GridSearchCV.html#sklearn.grid_search.GridSearchCV)?
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.
解决方法:
参数评分是0.14开发版中的新增内容,示例代码适用于该版本.您安装的scikit可能是版本0.13或更早版本,它没有评分参数.
内容总结
以上是互联网集市为您收集整理的python – TypeError:__ init __()得到一个意外的关键字参数’scoring’全部内容,希望文章能够帮你解决python – TypeError:__ init __()得到一个意外的关键字参数’scoring’所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。