简体   繁体   English

如何计算多类的精度、召回率和 f1 分数? 我们如何在交叉验证中使用 average='micro','macro' 等?

[英]How to calculate precision ,recall & f1 score for multiclass? How can we use average='micro','macro' etc. in cross validation?

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))

When I run this code, it gives me this error and when I try to print(scores['precision']) print like this, it gives a key error of precision.当我运行这段代码时,它给了我这个错误,当我尝试像这样print(scores['precision'])打印时,它给出了一个关键的精度错误。 Kindly suggest me how can I improve my code and also calculate multiple accuracies by using cross-validate for multiclass.请建议我如何改进我的代码并通过对多类使用交叉验证来计算多个精度。

if you google cross_validate you get scikit cross_validate .如果你谷歌cross_validate你会得到scikit cross_validate in the arguments for scoring, for dictionary it says:在评分参数中,对于字典,它说:

a dictionary with metric names as keys and callables as values.以度量名称作为键和可调用对象作为值的字典。

maybe you're having a hard time sending a callable with an argument.也许您很难发送带有参数的可调用对象。 try this:尝试这个:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何计算 K 折交叉验证的不平衡数据集的精度、召回率和 f1 分数? - How to compute precision,recall and f1 score of an imbalanced dataset for K fold cross validation? 如何获得sklearn的平均精度,召回率,f1,交叉验证的精度? - How to get average precision, recall, f1, accuracy of cross-validation with sklearn? 多类标签交叉验证的 F1 分数 - F1 score for multiclass labeling cross validation 如何在训练 SSD 后预测 Precision、Recall 和 F1 分数 - How to predict Precision, Recall and F1 score after training SSD 如何计算此模型的召回率、准确率和 f 分数? - how can I calculate recall, precision and f-score for this model? 如何计算实体预测的精度、召回率和 F1 - How to Calculate Precision, Recall, and F1 for Entity Prediction 微观宏观和加权平均值都具有相同的精度,召回率,f1分数 - micro macro and weighted average all have the same precision, recall, f1-score 多类CNN的宏指标(召回/ F1 ......) - Macro metrics (recall/F1…) for multiclass CNN 如何使用 MobileNet 计算 Multiclass-problem 的准确率、召回率、F1 和混淆矩阵 - How to compute precision, recall, F1 and confusion matrix of Multiclass-problem with MobileNet 精度,召回率,F1得分与sklearn相等 - Precision, recall, F1 score equal with sklearn
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM