could not determine class_counts_ from previously fitted classifier
See original GitHub issueDescribe the bug
When running visualizer, I am receiving a warning :
yellowbrick/classifier/base.py:232: YellowbrickWarning: could not determine class_counts_ from previously fitted classifier
which results in fitting again the classifier.
To Reproduce
from yellowbrick.classifier import ClassificationReport, ConfusionMatrix
from sklearn import datasets
from sklearn.model_selection import train_test_split
import xgboost as xgb
import matplotlib.pyplot as plt
X, y = datasets.load_iris(return_X_y=True)
x_train, x_val, y_train, y_val = train_test_split(
X,
y,
stratify=y,
test_size = 0.2)
model = xgb.XGBClassifier(objective ='multi:softprob',
num_class=3,
use_label_encoder=False,
enable_categorical=False,
n_estimators=10)
model.fit(x_train,
y_train,
early_stopping_rounds=10,
eval_set=[(x_train, y_train), (x_val, y_val)])
fig, ax = plt.subplots()
visualizer = ClassificationReport(model,
is_fitted=True)
visualizer.score(x_val, y_val)
visualizer.show()
Dataset
from sklearn import datasets
Expected behavior
Since, we declare is_fitted=True
, it should not fit again.
Traceback
/home/ggous/miniconda3/envs/sklearn/lib/python3.9/site-packages/yellowbrick/classifier/base.py:232: YellowbrickWarning: could not determine class_counts_ from previously fitted classifier
warnings.warn(
Desktop (please complete the following information):
- OS: Linux Mint
- Python Version : 3.9.12 miniconda
- Yellowbrick Version : 1.5
Additional context I think sometimes it takes too much time to fit again?
Issue Analytics
- State:
- Created a year ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
How to use the yellowbrick.exceptions.NotFitted function in ...
Use Snyk Code to scan source code in minutes - no build needed - and fix issues ... "could not determine class_counts_ from...
Read more >Source code for yellowbrick.classifier.confusion_matrix
If the model is not a classifier, an exception is raised. If the internal model is not fitted, it is fit when the...
Read more >[Titanic]Decision tree complete evaluation
Anything that cannot be imported from sklearn.metrics is now part of the private ... could not determine class_counts_ from previously fitted classifier ......
Read more >Can we use numpy array confusion matrix in Yellowbrick ...
You can pass the fitted model into Yellowbrick. The latest version of Yellowbrick checks whether the model is already fitted and will not...
Read more >SK Part 3: Model Evaluation
Commonly used evaluation metrics for a binary classifier are as follows: ... We do not need to adjust prediction score (in fact, we...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@lwgray thank you for adding those suggestions!
@ggous if you’re in a Jupyter notebook, this StackOverflow post has some suggestions for preventing the image from being rendered. Otherwise
clear_figure
as @lwgray mentioned is probably your best bet.This code address both concerns but @bbengfort maybe you have a better trick to stop showing the plot. I feel like we answered this question before.