【问题标题】:How to calculate precision ,recall & f1 score for multiclass? How can we use average='micro','macro' etc. in cross validation?如何计算多类的精度、召回率和 f1 分数?我们如何在交叉验证中使用 average='micro','macro' 等?
【发布时间】:2021-11-02 15:28:39
【问题描述】:
TypeError: unsupported operand type(s) for /: 'dict' and 'int'

`

**Here is my code** 
x = df[header] 
clf=GaussianNB()
      
scoring = {
    'accuracy' : make_scorer(accuracy_score),
    'precision' : make_scorer(precision_score,average = 'micro'),
    'recall' : make_scorer(recall_score,average = 'micro'),
    'f1_score' : make_scorer(f1_score,average = 'micro')
} 
            
scores = cross_validate(clf, x, y, scoring=scoring, cv=5)
        
print(np.mean(scores))

当我运行这段代码时,它给了我这个错误,当我尝试像这样打印print(scores['precision']) 时,它给出了一个关键的精度错误。请建议我如何改进我的代码并通过对多类使用交叉验证来计算多个精度。

【问题讨论】:

    标签: python machine-learning cross-validation multiclass-classification precision-recall


    【解决方案1】:

    如果你用谷歌搜索cross_validate,你会得到scikit cross_validate。在评分的参数中,对于字典它说:

    以指标名称为键、可调用对象为值的字典。

    也许您很难发送带有参数的可调用对象。试试这个:

    scoring = {'accuracy' : lambda: make_scorer(accuracy_score),
                   ...
                  } 
    

    【讨论】:

      猜你喜欢
      • 2018-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-18
      • 2017-03-14
      • 2015-10-03
      • 2019-11-23
      • 2017-05-28
      相关资源
      最近更新 更多