Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plot_metric does not work with Booster #4702

Closed
js850 opened this issue Oct 21, 2021 · 5 comments
Closed

plot_metric does not work with Booster #4702

js850 opened this issue Oct 21, 2021 · 5 comments

Comments

@js850
Copy link
Contributor

js850 commented Oct 21, 2021

plot_metric works with LGBMModel, but not with lightgbm.basic.Booster.

This seems to be by design, but seems like a clear gap in functionality.

https://github.com/microsoft/LightGBM/blob/master/python-package/lightgbm/plotting.py

    if isinstance(booster, LGBMModel):
        eval_results = deepcopy(booster.evals_result_)
    elif isinstance(booster, dict):
        eval_results = deepcopy(booster)
    else:
        raise TypeError('booster must be dict or LGBMModel.')

I'm just getting started with lightgbm, is there an easy workaround?

@js850
Copy link
Contributor Author

js850 commented Oct 21, 2021

After more hunting I found the workaround from this issue: #1491 which points to this example

This took me a surprisingly long time to figure out. I would suggest updating the exception message from plot_metric to give instructions on how to use the method with Booster

something like

if isinstance(booster, Booster):
    raise Exception("to plot the metrics for a Booster type, first output the metrics using evals_result then pass that in to this method as `booster`")

@shiyu1994
Copy link
Collaborator

@js850 Thanks for figuring that out. Good suggestion to make usage of plot_metric more clear. Would you like to open a pull request for this? If not, I can help to do so.

@StrikerRUS StrikerRUS changed the title pot_metric does not work with Booster plot_metric does not work with Booster Oct 22, 2021
@js850
Copy link
Contributor Author

js850 commented Oct 23, 2021

Thanks for the suggestion, @shiyu1994. I have created a PR to address this: #4709

@StrikerRUS
Copy link
Collaborator

Closed via #4709.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity since it was closed.
To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues
including a reference to this.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants