sklearn plot confusion matrix with labels

前端 未结 7 1234
生来不讨喜
生来不讨喜 2020-11-29 19:09

I want to plot a confusion matrix to visualize the classifer\'s performance, but it shows only the numbers of the labels, not the labels themselves:

from skl         


        
7条回答
  •  不知归路
    2020-11-29 19:31

        from sklearn.metrics import confusion_matrix
        import seaborn as sns
        import matplotlib.pyplot as plt
        model.fit(train_x, train_y,validation_split = 0.1, epochs=50, batch_size=4)
        y_pred=model.predict(test_x,batch_size=15)
        cm =confusion_matrix(test_y.argmax(axis=1), y_pred.argmax(axis=1))  
        index = ['neutral','happy','sad']  
        columns = ['neutral','happy','sad']  
        cm_df = pd.DataFrame(cm,columns,index)                      
        plt.figure(figsize=(10,6))  
        sns.heatmap(cm_df, annot=True)
    

提交回复
热议问题