0 Posted 2022-03-31Updated 2024-01-15Python / Plot2 minutes read (About 263 words)Python GAM to fitPython GAM to fit Source: pygam import numpy as npimport matplotlib.pyplot as pltfrom pygam import LinearGAM, s, tefrom pygam.datasets import mcycle# X = np.array([ [i] for i in Cell_fit.Class_size.to_list()])# y = np.array(Cell_fit.Size.to_list())X, y = mcycle(return_X_y=True)gam = LinearGAM(n_splines=25).gridsearch(X, y)XX = gam.generate_X_grid(term=0, n=500)plt.plot(XX, gam.predict(XX), 'r--')plt.plot(XX, gam.prediction_intervals(XX, width=.95), color='b', ls='--')plt.scatter(X, y, facecolor='gray', edgecolors='none')plt.title('95% prediction interval'); © pyGAM Regression by numpy Source: W3 school x = X.flatten()y = y.to_list()mymodel = np.poly1d(np.polyfit(x, y, 3))myline = np.linspace(2, 95, 100)plt.scatter(x, y)plt.plot(myline, mymodel(myline))plt.show() Other X, y = mcycle(return_X_y=True)gam = LogisticGAM(f(0) + s(1) + s(2)).gridsearch(X, y)fig, axs = plt.subplots(1, 3)titles = ['student', 'balance', 'income']for i, ax in enumerate(axs): XX = gam.generate_X_grid(term=i) pdep, confi = gam.partial_dependence(term=i, width=.95) ax.plot(XX[:, i], pdep) ax.plot(XX[:, i], confi, c='r', ls='--') ax.set_title(titles[i]); Python GAM to fithttps://karobben.github.io/2022/03/31/Python/py-gam/AuthorKarobbenPosted on2022-03-31Updated on2024-01-15Licensed under#Data SciencePythonPlotRegression