-
Notifications
You must be signed in to change notification settings - Fork 280
Description
Summary
pyGAM is a powerful library for building Generalized Additive Models (GAMs) in Python, designed with a familiar API for users of scikit-learn and SciPy.
However, new users often struggle to create their first working model due to a lack of a minimal end-to-end example covering data generation, model fitting, and prediction.
This issue proposes adding a beginner-friendly example script demonstrating regression with pyGAM.
Objective
Create a simple example that demonstrates:
Generating or loading sample data
Training a GAM regression model
Making predictions
Visualizing results
Running successfully with minimal setup
Why This Matters
✨ Improves onboarding for new users
✨ Helps users coming from scikit-learn ecosystem
✨ Demonstrates core functionality quickly
✨ Reduces repetitive support questions
✨ Encourages adoption in research & industry
Proposed Changes
Add a new example file:
examples/basic_gam_regression.py
Example Implementation (Starter Code)
"""
Basic Regression Example using pyGAM
"""
import numpy as np
import matplotlib.pyplot as plt
from pygam import LinearGAM, s
Generate synthetic nonlinear data
np.random.seed(0)
X = np.linspace(0, 5, 100)
y = np.sin(X) + np.random.normal(scale=0.2, size=100)
X = X.reshape(-1, 1)
Fit a GAM model
gam = LinearGAM(s(0)).fit(X, y)
Predict
X_pred = np.linspace(0, 5, 200).reshape(-1, 1)
y_pred = gam.predict(X_pred)
Plot results
plt.scatter(X, y, label="Data", alpha=0.6)
plt.plot(X_pred, y_pred, color="red", label="GAM Fit")
plt.title("pyGAM Regression Example")
plt.legend()
plt.show()
Steps to Complete
Install dependencies
pip install pygam matplotlib numpy
erify the example runs on the latest pyGAM version (≥ 0.12.0)
Add clear comments explaining each step
Place file in the examples directory
(Optional) Link example in README or docs
Acceptance Criteria
✔ Script runs without errors
✔ Uses only public pyGAM APIs
✔ Beginner-friendly comments included
✔ Demonstrates full workflow (data → model → prediction → plot)
✔ Added to examples folder
✔ Compatible with current release