Reputation: 413
I would like to change the average parameter of the precision metric because this error occurs
"ValueError: Target is multiclass but average='binary'. Please choose another average setting."
I have read the official website but I couldn't find an answer in terms of using cross_validate function.
clf = RandomForestClassifier()
scoring = ['accuracy', 'precision']
scores = cross_validate(clf, X, Y, scoring=scoring, cv=10, return_train_score=False, n_jobs=-1)
Any idea how to handle this?
Upvotes: 6
Views: 1503
Reputation: 1614
Use make_scorer
which allows you to specify parameters for your individual scoring metrics, then use a dictionary to map multiple metrics to names:
from sklearn.metrics import accuracy_score, precision_score, make_scorer
scoring = {'Accuracy': make_scorer(accuracy_score),
'Precision': make_scorer(precision_score, average='None')}
scores = cross_validate(clf, X, Y, scoring=scoring, ...)
Refer this example
Upvotes: 8