小编fal*_*ll2的帖子

Sci-kit学习如何打印混淆矩阵的标签?

所以我正在使用sci-kit学习分类一些数据.我有13个不同的类值/分类来分类数据.现在我已经能够使用交叉验证并打印混淆矩阵.但是,它只显示TP和FP等没有classlabels,所以我不知道哪个类是什么.以下是我的代码和输出:

def classify_data(df, feature_cols, file):
    nbr_folds = 5
    RANDOM_STATE = 0
    attributes = df.loc[:, feature_cols]  # Also known as x
    class_label = df['task']  # Class label, also known as y.
    file.write("\nFeatures used: ")
    for feature in feature_cols:
        file.write(feature + ",")
    print("Features used", feature_cols)

    sampler = RandomOverSampler(random_state=RANDOM_STATE)
    print("RandomForest")
    file.write("\nRandomForest")
    rfc = RandomForestClassifier(max_depth=2, random_state=RANDOM_STATE)
    pipeline = make_pipeline(sampler, rfc)
    class_label_predicted = cross_val_predict(pipeline, attributes, class_label, cv=nbr_folds)
    conf_mat = confusion_matrix(class_label, class_label_predicted)
    print(conf_mat)
    accuracy = accuracy_score(class_label, class_label_predicted)
    print("Rows classified: " + str(len(class_label_predicted)))
    print("Accuracy: {0:.3f}%\n".format(accuracy * 100)) …
Run Code Online (Sandbox Code Playgroud)

python machine-learning confusion-matrix scikit-learn

4
推荐指数
2
解决办法
8554
查看次数