question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make it easy to use different color for mean in plot_partial_dependence

See original GitHub issue

It would be great to be able to give a different color or scheme to the average in pd plots. For example, this plot is actually quite interesting in terms of ICE showing trends that are not in the average: image (yes this is real data and I’m excited that ICE is useful!) I know which one is the average, but it’s kinda hard to see. If I set subsample to the default, it’s certainly impossible to see. I tried to get the line out of the lines_ but I’m struggling a bit (and I think something is off there EDIT: I was on a pre #18359 commit).

Using the example from the docs you can do:

from sklearn.ensemble import RandomForestRegressor
from sklearn.datasets import fetch_california_housing
from sklearn.inspection import plot_partial_dependence

X, y = fetch_california_housing(return_X_y=True, as_frame=True)
features = ['MedInc', 'AveOccup', 'HouseAge', 'AveRooms', 'AveOccup']
est = RandomForestRegressor(n_estimators=10)
est.fit(X, y)
display = plot_partial_dependence(
       est, X, features, kind="both", subsample=100,
       n_jobs=3, grid_resolution=20, random_state=0
)
display.plot(n_cols=5)
for i in range(display.lines_.shape[1]):
    display.lines_[0,i,-1].set_color('k')
    display.axes_[0, i].legend()  # needed to update the legend color

image

I don’t think the order of the lines in lines_ is documented.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
glemaitrecommented, Dec 8, 2020

We need to find the right API because we already have line_kw. I don’t know if it would make sense to deprecate it and add ice_lines_kw and pd_line_kw?

1reaction
NicolasHugcommented, Dec 9, 2020

or not deprecate but let ice_lines_kw and pd_line_kw take priority over line_kw (i.e. override)? This way one can still control all lines with line_kw while having more fine-grain control with the new params

Read more comments on GitHub >

github_iconTop Results From Across the Web

Partial dependence plots with Scikit-learn
PartialDependenceDisplay allows us to plot a subset of individual predictions along with the average to get a better sense of the data:
Read more >
Advanced Plotting With Partial Dependence
The partial dependence curves can be plotted for the multi-layer perceptron. In this case, line_kw is passed to from_estimator to change the color...
Read more >
pdp: Partial Dependence Plots
Character string specifying the color to use for the partial dependence function when plot.pdp = TRUE. Default is "red". pdp.size.
Read more >
MATLAB plotPartialDependence
This MATLAB function computes and plots the partial dependence between the predictor variables listed in Vars and the responses predicted by using the ......
Read more >
how to set h20 partial_plot partial dependence plot figsize
Try adding the parameter figsize=(10, 6) (here this is 10 x 6 inches) or in a separate line of code model.figure_.set_size_inches(10, 6) ....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found