[英]how to score precision, recall and f1-score in a multi-class dataset using cross-validate?
此代碼適用於具有 2 個類但不適用於多類的數據集
scoring = {'accuracy' : make_scorer(accuracy_score),
'precision' : make_scorer(precision_score),
'recall' : make_scorer(recall_score),
'f1_score' : make_scorer(f1_score)}
scores = cross_val_score(gnb,x,y, cv=5, scoring=scoring)
print(scores)
錯誤顯示
ValueError: For evaluating multiple scores, use sklearn.model_selection.cross_validate instead. {'accuracy': make_scorer(accuracy_score), 'precision': make_scorer(precision_score, average=None), 'recall': make_scorer(recall_score), 'f1_score': make_scorer(f1_score)} was passed
當我檢查代碼並像這樣更改它時
scores = cross_val_score(gnb,x,y, cv=5, scoring='precision')
錯誤顯示
ValueError: Target is multiclass but average='binary'. Please choose another average setting, one of [None, 'micro', 'macro', 'weighted'].
當我在make_scorer
中設置average
時它不起作用
對 f1 使用評分 function ' f1_macro
' 或 ' f1_micro
'。
同樣,“ recall_macro
”或“ recall_micro
”用於召回。
在計算精度或召回率時,定義正 class 很重要,但在多類數據集中,很難定義它。
因此,應該計算每個 class 值(即迭代每個值並將其視為正類)的平均精度(召回)。
編輯。
嘗試使用以下代碼(微平均精度、召回率、f1)。
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')}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.