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