GithubHelp home page GithubHelp logo

Comments (5)

lwgray avatar lwgray commented on June 1, 2024 1

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.

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)])

# Specify class counts on the model
model.class_counts_ = 3
fig, ax = plt.subplots()
visualizer = ClassificationReport(model, is_fitted=True)
visualizer.score(x_val, y_val)

# Clear Figure works but @bbengfort might have a better approach
visualizer.show('test.png', clear_figure=True);

from yellowbrick.

bbengfort avatar bbengfort commented on June 1, 2024 1

@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.

from yellowbrick.

bbengfort avatar bbengfort commented on June 1, 2024

@ggous thank you for using Yellowbrick and for reporting the issue that you found to us! I hope that you're finding Yellowbrick useful.

In order to use the ClassificationReport the model needs the class_counts_ learned attribute. This appears in most scikit-learn classifiers. I believe the xgb package adds learned attributes if it understands it's in a scikit-learn context. I am not really sure why it doesn't have it when you fit the model and after -- I don't use the xgb package very often.

Could you try directly adding class_counts_ to the model before creating the visualizer to see if that helps things?

@lwgray do you have experience using xgb -- if so, perhaps you could comment on this issue?

from yellowbrick.

ggous avatar ggous commented on June 1, 2024

Hi bbengfort.

I can't find an attribute of class_counts_ in xgb.
I am not sure how to add it before the visualizer.

from yellowbrick.

ggous avatar ggous commented on June 1, 2024

Also, is there a way for only saving the visualizer without showing it?

I am using visualizer.show(outpath='./file.png')

but I want only to save , not to display the result plot.

from yellowbrick.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.