[英]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.