DistrictDataLabs / yellowbrick

Visual analysis and diagnostic tools to facilitate machine learning model selection.
http://www.scikit-yb.org/
Apache License 2.0
4.28k stars 557 forks source link

ConfusionMatrix visualizer error with sklearn models #1292

Open AmericaBG opened 1 year ago

AmericaBG commented 1 year ago

Hello! I try to do a simple example like:

from sklearn.datasets import load_digits
from sklearn.model_selection import train_test_split as tts
from sklearn.linear_model import LogisticRegression
from yellowbrick.classifier import ConfusionMatrix

# We'll use the handwritten digits data set from scikit-learn.
# Each feature of this dataset is an 8x8 pixel image of a handwritten number.
# Digits.data converts these 64 pixels into a single array of features
digits = load_digits()
X = digits.data
y = digits.target

X_train, X_test, y_train, y_test = tts(X, y, test_size =0.2, random_state=11)

model = LogisticRegression(multi_class="auto", solver="liblinear")

# The ConfusionMatrix visualizer taxes a model
cm = ConfusionMatrix(model, classes=[0,1,2,3,4,5,6,7,8,9])

# Fit fits the passed model. This is unnecessary if you pass the visualizer a pre-fitted model
cm.fit(X_train, y_train)

# To create the ConfusionMatrix, we need some test data. Score runs predict() on the data
# and then creates the confusion_matrix from scikit-learn.
cm.score(X_test, y_test)

# How did we do?
cm.show()

The following error raised: AttributeError: 'LogisticRegression' object has no attribute 'classes'

This type of confussion matrix visualization worked a few days ago, could it be due to incompatibility between library versions?

Thank you very much in advance!

rebeccabilbro commented 1 year ago

Hello @AmericaBG and thank you for using Yellowbrick. In order to help you, we will need you to provide information about your system and the package versions you are using locally, specifically:

If you could also provide your scikit-learn version, that would be very helpful.

AmericaBG commented 1 year ago

Hi Rebecca, thanks for your reply! The info is as follow:

Thank you very much!!

El mié, 14 dic 2022 a las 15:55, Rebecca Bilbro @.***>) escribió:

Hello @AmericaBG https://github.com/AmericaBG and thank you for using Yellowbrick. In order to help you, we will need you to provide information about your system and the package versions you are using locally, specifically:

  • Your operating system: [e.g. macOS]
  • Your Python Version [e.g. 2.7, 3.6, miniconda]
  • Your Yellowbrick Version [e.g. 0.7]

If you could also provide your scikit-learn version, that would be very helpful.

— Reply to this email directly, view it on GitHub https://github.com/DistrictDataLabs/yellowbrick/issues/1292#issuecomment-1351562307, or unsubscribe https://github.com/notifications/unsubscribe-auth/AL4YAXHJE5YZMCABLKOOLHDWNHNV5ANCNFSM6AAAAAAS6LLAF4 . You are receiving this because you were mentioned.Message ID: @.***>

ArSenic04 commented 1 year ago

Use ClassificationReport instead but I cannot find where to edit can you help me with that?