简体   繁体   中英

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. 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 . 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),
               ...
              } 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM