I'm trying to test the pygam library, starting with a tutorial that i found here. But, when i try to do use the command
LogisticGam.generate_X_grid(gam)
i get an error.
i'm using pygam 0.9.1
my code
import pandas as pd
from pygam import LogisticGAM
from sklearn.datasets import load_breast_cancer
import matplotlib.pyplot as plt
data = load_breast_cancer()
df = pd.DataFrame(data.data, columns=data.feature_names)[['mean radius', 'mean texture', 'mean perimeter', 'mean area','mean smoothness', 'mean compactness']]
target_df = pd.Series(data.target)
X = df[['mean radius', 'mean texture', 'mean perimeter', 'mean area','mean smoothness', 'mean compactness']]
y = target_df
gam = LogisticGAM().fit(X, y)
> XX = generate_X_grid(gam) #i can't use the method that way so i do the following
> XX = LogisticGam.generate_X_grid(gam)
plt.rcParams['figure.figsize'] = (28, 8)
fig, axs = plt.subplots(1, len(data.feature_names[0:6]))
titles = data.feature_names
for i, ax in enumerate(axs):
pdep, confi = gam.partial_dependence(XX, feature=i+1, width=.95)
ax.plot(XX[:, i], pdep)
ax.plot(XX[:, i], confi[0][:, 0], c='grey', ls='--')
ax.plot(XX[:, i], confi[0][:, 1], c='grey', ls='--')
ax.set_title(titles[i])
plt.show()
the error i get is:
TypeError: GAM.generate_X_grid() missing 1 required positional argument "term"
The term must be the "gam" variable, but for some reason the method not recognize it I think maybe it's a version change, but i can't find useful information about how to use it. If you have dealing with same error please tell me what i'm doing wrong. Thanks