SauceCat / PDPbox

python partial dependence plot toolbox
http://pdpbox.readthedocs.io/en/latest/
MIT License
840 stars 129 forks source link

Request help in using the library #88

Open sissaNassir opened 1 year ago

sissaNassir commented 1 year ago

Hello! I'm trying to use PDPbox but It doesn't plot the figure and I don't understand

I'm using this dataset https://www.kaggle.com/datasets/mathan/fifa-2018-match-statistics

the code is

y = (fifa['Man of the Match'] == "Yes") # Convert from string "Yes"/"No" to binary
feature_names = [i for i in fifa.columns if fifa[i].dtype in [np.int64]]
X = fifa[feature_names]
train_X, val_X, train_y, val_y = train_test_split(X, y, random_state=1)
my_model = RandomForestClassifier(n_estimators=100, random_state=0).fit(train_X, train_y)

Then I consider the PDP for goal scored and I write:

from pdpbox import pdp, info_plots #A
feature_to_plot = 'Goal Scored' #B
pdp_dist = pdp.PDPIsolate(my_model, val_X, feature_names,feature_to_plot,'Goal Scored')

fig, axes = pdp_dist.plot(
    center=True,
    plot_lines=True,
    frac_to_plot=1,
    cluster_method='accurate',
    plot_pts_dist=True,
    to_bins=False,
    show_percentile=False,
    which_classes=None,
    figsize=None,
    dpi=300,
    ncols=2,
    plot_params={"pdp_hl": True, "line": {"hl_color": "#f46d43"}},
    engine='plotly',
    template='plotly_white',
)
fig

But it doesn't plot any figure, where is the error?

Thank you

SauceCat commented 1 year ago

@silviazandoli are you plotting this inside jupyter notebook? Or you just run the script?

sissaNassir commented 11 months ago

Yes, I run this in a jupyter notebook through Google Colab @SauceCat