pythonpandasmatplotlibgraphconfusion-matrix

Sklearn module missing and unsure what to use instead?


I'm currently following this guide https://www.geeksforgeeks.org/rainfall-prediction-using-machine-learning-python/

However. I am getting this error for the following lines of code.

for i in range(3):

    models[i].fit(X, Y)


    print(f'{models[i]} : ')


    train_preds = models[i].predict_proba(X) 

    print('Training Accuracy : ', metrics.roc_auc_score(Y, train_preds[:,1]))


    val_preds = models[i].predict_proba(X_val) 

    print('Validation Accuracy : ', metrics.roc_auc_score(Y_val, val_preds[:,1]))

    print()



    metrics.plot_confusion_matrix(models[2], X_val, Y_val)

    plt.show()

I get this error: "AttributeError: module 'sklearn.metrics' has no attribute 'plot_confusion_matrix'. Did you mean: 'pair_confusion_matrix'?"

Apparently, the plot confusion matrix was deprecated, but I am unsure of what to do now as I do need this graph.

I hope you can help!!

Have tried looking through the documentation, but cannot find what is replacing this old function.


Solution

  • You should try to use sklearn.metrics.ConfusionMatrixDisplayas mentionned here: ImportError: cannot import name 'plot_confusion_matrix' from 'sklearn.metrics'