简体   繁体   中英

classification report for multilabel text classification?

I'm working on multilabel text classification. I'm tried to print the classification report for the machine learning but its print for each class alone. how I can get the classification report for all classes together? This part of the code

this code for the labels

categories = list(data_raw.columns.values)
categories = categories[1:]

The Evaluation:

def modelEvaluation(predictions, y_test_set):
    print("\nAccuracy on validation set: {:.4f}".format(accuracy_score(y_test_set, predictions)))
    print("\nClassification report : \n", metrics.classification_report(y_test_set, predictions))
    print("\nConfusion Matrix : \n", multilabel_confusion_matrix(y_test_set, predictions))

and this for ML

from sklearn.svm import LinearSVC


SVC_pipeline = Pipeline([
                    ('clf', OneVsRestClassifier(LinearSVC(), n_jobs=1)),
            ])


for category in categories:
    printmd('**Processing {} comments...**'.format(category))
    
    # Training logistic regression model on train data
    SVC_pipeline.fit(x_train, train[category])
    
    # calculating test accuracy
    prediction = SVC_pipeline.predict(x_test)
    print('Test accuracy is {}'.format(accuracy_score(test[category], prediction)))
    print("\n")
    
    modelEvaluation(prediction, test[category])

if I tried to print the classification report alone like the below code, it gives me the result for the last class

from sklearn.metrics import classification_report
print("\nClassification report : \n", metrics.classification_report(test[category], prediction))

Use without test[category] and provide the whole test set which contains all classes that you build your model for.

print("\nClassification report : \n", metrics.classification_report(y_test, predictions))

Where y_test is ground truth labels (True outputs) for test set X_test .

You are passing test set ( X_test ) instead of labels ( y_test ) for that test set.

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