为了获得带有病态学习的决策树,我需要对数据框进行标签编码。
S02Q01_Gender S02Q02_Age_rec S02Q03A_Region S02Q03B_Settlement_type S02Q03C_Province S02Q10A_Employment S02Q11_Professional_field Segment Cluster
0 Female 12-19 Marrakesh Urban Casablanca-Settat Student None Class1
1 Male 65 or above Marakesh Rural El Jadida My Employed, part-time Property Class2
...
但是,为了在混淆矩阵上正确绘制它,我需要保存target
列的标签。
我试过了:
y_test_dencoded = label_encoder.inverse_transform(y_test)
y_pred_dencoded = label_encoder.inverse_transform(y_pred)
cnf_matrix = metrics.confusion_matrix(y_test_dencoded, y_pred_dencoded, labels=None, sample_weight=None)
并绘制它:
import seaborn as sn
import pandas as pd
import matplotlib.pyplot as plt
df_cm = pd.DataFrame(cnf_matrix, index = [i for i in set(y_test_dencoded)],
columns = [i for i in set(y_pred_dencoded)])
plt.figure(figsize = (10,7))
ax = sn.heatmap(df_cm, annot=True)
bottom, top = ax.get_ylim()
ax.set_ylim(bottom + 0.5, top - 0.5)
它返回一个混淆矩阵,但我不知道我是否很好地标记它......