简体   繁体   中英

Python Confusion_matrix function did not work

I tried to make a function to get the confusion matrix. It did not show up even though I tried so many times. Could you let me know what went wrong?

Thank you so much

def draw_cm( actual, predicted ) :
    cm = confusion_matrix(Y_test, y_predict)
    sns.heatmap(cm, annot= True,  fmt='.2f', xticklabels = [0,1] , yticklabels = [0,1] )
    plt.ylabel('Y_test')
    plt.xlabel('y_predict')
    plt.show()
draw_cm( actual, predicted )

Basically you have placed wrong variables in your code

def draw_cm( actual, predicted ) :
    cm = confusion_matrix(actual, predicted ) ---> Fixed here
    sns.heatmap(cm, annot= True,  fmt='.2f', xticklabels = [0,1] , yticklabels = [0,1] )
    plt.ylabel('Y_test')
    plt.xlabel('y_predict')
    plt.show()

draw_cm( actual, predicted )

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