python - Scikit multi-class classification metrics, classification report -
i using scikit learn 0.15.2 multi-class classification problem. getting lot of deprecationwarnings follows when following examples like: scikit 0.14 multi label metrics until started use multilabelbinarizer:
"deprecationwarning: direct support sequence of sequences multilabel representation unavailable version 0.17. use sklearn.preprocessing.multilabelbinarizer convert label indicator representation."
however, cannot find way classification report (with precision, recall, f-measure) work it, possible shown here: scikit 0.14 multi label metrics
i tried use inverse_transform below, gives classification_report gives warnings again, 0.17 code break.
how can measures multi-class classification problem?
example code:
import numpy np sklearn.multiclass import onevsrestclassifier sklearn.preprocessing import multilabelbinarizer sklearn.svm import linearsvc sklearn.metrics import classification_report # simple data: x_train = np.array([[0,0,0], [0,0,1], [0,1,0], [1,0,0], [1,1,1]]) y_train = [[1], [1], [1,2], [2], [2]] # use multilabelbinarizer , train multi-class classifier: mlb = multilabelbinarizer(sparse_output=true) y_train_mlb = mlb.fit_transform(y_train) clf = onevsrestclassifier(linearsvc()) clf.fit(x_train, y_train_mlb) # classification_report, here did not find way use y_train_mlb, # getting lot of deprecationwarnings predictions_test = mlb.inverse_transform(clf.predict(x_train)) print classification_report(y_train, predictions_test) # predict new example: print mlb.inverse_transform(clf.predict(np.array([0,1,0])))
it seems have run classification report binarized labels:
print classification_report(y_train_mlb, clf.predict(x_train))
Comments
Post a Comment