Please tell me how to resolve the error message "cannot import name 'plot_confusion_matrix 'from 'sklearn.metrics' in scikit-learn.

Asked 1 years ago, Updated 1 years ago, 296 views

Using SVM's regressoar, we are trying to conduct an assessment analysis of financial markets.
After coding with reference to the text, the last line plot_confusion_matrix, plot_roc_curve failed to proceed (message content is as title).

I googled the error message, updated the PIP and sciket-learn, and called the kernel RESTART, but the situation remains the same.

By the way, pip is (22.3.1) and scicket-learn is (1.2.0).

Could someone give me some advice?
By the way, the contents of the coding are as follows.

Thank you for your cooperation.

#Base Libraries
import pandas aspd
import numpy as np
import matplotlib.pyplot asplt
plt.style.use('fivethirtight')

# preprocessing
from sklearn.preprocessing import MinMaxScaler, RobustScaler
from sklearn.pipeline import Pipeline
from sklearn.model_selection import train_test_split, TimeSeriesSplit, GridSearchCV

# SVM
from sklearn.svm import SVR

# Metrics
from sklearn.metrics import r2_score, mean_squared_error, mean_absolute_error, accurability_score
from sklearn.metrics import acuity_score, classification_report, confusion_matrix
from sklearn.metrics import plot_confusion_matrix, auc, roc_curve, plot_roc_curve**

python scikit-learn

2022-12-20 09:18

1 Answers

plot_confusion_matrix is scheduled to be discarded (deprecated) in the scikit-learn 1.0.0 version, and it seems that it was actually deleted (removed) in the 1.2.0 version.
Try changing it to not use it or downgrading it to a version earlier than 1.2.0 if you want to use it.Is it before 1.1.3?
Release history scikit-learn-PyPI

Version 1.0.0
sklearn.metrics

  • API Change metrics.ConfusionMatrixDisplayexposes two class methodsfrom_estimator and from_preditsallowing to create a confusion matrix plot using the demonstratordictations.metrics.plot_confusion_matrixis decremented in favorite of these two class methods and will be removed in 1.2.#18543by Guillaume Lemeritre.

If you delete plot_confusion_matrix from the source of the question, you will get an error that plot_roc_curve cannot import the same way.There is no such description in the document, but the 1.2.0 version of API Reference and metrics.plot_det_curve with similar names after the description above have been removed as well.

The 1.1.3 version of API Reference seems to have a description left.
Plotting


2022-12-20 09:22

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.