简体   繁体   English

多标签文本分类的分类报告?

[英]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.我试图打印机器学习的分类报告,但它只打印每个 class 。 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这对于 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如果我尝试像下面的代码一样单独打印分类报告,它会给我最后一个 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.使用test[category]并提供包含您构建 model 的所有类的整个测试集。

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

Where y_test is ground truth labels (True outputs) for test set X_test .其中y_test是测试集X_test的真实标签(真实输出)。

You are passing test set ( X_test ) instead of labels ( y_test ) for that test set.您正在通过测试集 ( X_test ) 而不是该测试集的标签 ( y_test )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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