corss_val_score的scoring='accuracy'可以执行,使用其它参数报错

  统计/机器学习 监督式学习 模型验证 Python    浏览次数:4064        分享
0
C:\Users\wwwwww>python
Python 3.6.1 |Anaconda 4.4.0 (64-bit)| (default, May 11 2017, 13:25:24) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import load_iris
>>> from sklearn.ensemble import RandomForestClassifier
>>> forest = RandomForestClassifier(n_estimators=100,random_state=1)
>>> cross_val_score(forest,load_iris().data,load_iris().target,scoring='accuracy',cv=5)
array([ 0.96666667, 0.96666667, 0.93333333, 0.96666667, 1. ])
>>> cross_val_score(forest,load_iris().data,load_iris().target,scoring='precision',cv=5)
Traceback (most recent call last):
  File "", line 1, in
  File "E:\dsj-software\Anaconda3-4.4.0\lib\site-packages\sklearn\model_selection\_validation.py", line 140, in cross_val_score
    for train, test in cv_iter)
  File "E:\dsj-software\Anaconda3-4.4.0\lib\site-packages\sklearn\externals\joblib\parallel.py", line 758, in __call__
    while self.dispatch_one_batch(iterator):
  File "E:\dsj-software\Anaconda3-4.4.0\lib\site-packages\sklearn\metrics\classification.py", line 1018, in precision_recall_fscore_support
    "choose another average setting." % y_type)
ValueError: Target is multiclass but average='binary'. Please choose another average setting.
>>>
 

weihong   2019-12-08 13:50



   1个回答 
1


ValueError: Target is multiclass but average='binary'. Please choose another average setting.

错误信息已经告诉你了,你在做多元分类,但是你用的是二元分类的scoring,所以报错了

SofaSofa数据科学社区DS面试题库 DS面经

wxw_pku   2019-12-08 16:53

谢谢 - weihong   2019-12-09 09:44


  相关讨论

logistic回归有哪些指标可以评价模型效果?

怎么用KS值来评价二元分类器?

机器学习中lift的概念是什么?怎么用来评价模型?

多元分类可以用accuracy吗?

precision-recall曲线下面积有什么意义?

测试误差小于训练误差,是为什么?

有顺序的多元分类模型应该用评判标准?

分类中的F1精度、F2精度、F3精度是什么意思?

多元分类问题有没有F1?

二元分类问题中经常提到的TP,TN,FN,FP都是什么意思?

  随便看看

python里怎么表示科学计数法?

为什么神经网络模型不用交叉验证?

K-means怎么选K?

为什么梯度的反方向是函数下降最快的方向?

sklearn分类模型中预测结果怎么调整概率的阈值