[英]How to compute precision,recall and f1 score of an imbalanced dataset for K fold cross validation?
[英]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))
当我运行这段代码时,它给了我这个错误,当我尝试像这样print(scores['precision'])
打印时,它给出了一个关键的精度错误。 请建议我如何改进我的代码并通过对多类使用交叉验证来计算多个精度。
如果你谷歌cross_validate
你会得到scikit cross_validate 。 在评分参数中,对于字典,它说:
以度量名称作为键和可调用对象作为值的字典。
也许您很难发送带有参数的可调用对象。 尝试这个:
scoring = {'accuracy' : lambda: make_scorer(accuracy_score),
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.