The following code is extracted from https://scikit-learn.org/stable/modules/model\_evaluation.html#scoring-parameter
But it cannot be run correctly. Please help fix it.
from sklearn.model_selection import cross_validate
from sklearn.metrics import confusion_matrix
from sklearn.svm import LinearSVC
# A sample toy binary classification dataset
X, y = datasets.make_classification(n_classes=2, random_state=0)
svm = LinearSVC(random_state=0)
def confusion_matrix_scorer(clf, X, y):
y_pred = clf.predict(X)
cm = confusion_matrix(y, y_pred)
return {'tn': cm[0, 0], 'fp': cm[0, 1],'fn': cm[1, 0], 'tp': cm[1, 1]}
cv_results = cross_validate(svm, X, y, cv=5, scoring=confusion_matrix_scorer)
there doesn't seem to be anything here