Functional Partial Least Squares
Project description
FPLS: Functional Partial Least Squares
A Python package for functional regression using Partial Least Squares (PLS), implementing the methods from:
Babii, A., Carrasco, M., & Tsafack, I. (2023). "Functional Partial Least-Squares: Adaptive Estimation and Inference." Journal of the American Statistical Association.
Overview
This package provides a clean, scikit-learn-style API for fitting functional PLS regression models with adaptive component selection. The core algorithm uses a conjugate gradient method to solve the functional PLS problem, with integrals approximated via Riemann sums on uniform grids.
Key Features:
- FunctionalPLS estimator with
.fit(),.predict(), and.fit_predict()methods - Adaptive early stopping for automatic component selection
- Efficient conjugate gradient algorithm for functional data
- Support for both NumPy arrays and Pandas DataFrames
Installation
Install in development (editable) mode:
cd fpls
pip install -e .
To include optional dependencies for model selection and plotting:
pip install -e ".[all]"
Quick Start
Basic Usage
import numpy as np
from fpls import FunctionalPLS
# Generate synthetic functional data
n_samples = 200
n_grid_points = 50
X = np.random.randn(n_samples, n_grid_points)
beta_true = np.sin(np.linspace(0, 2*np.pi, n_grid_points))
y = X @ beta_true + np.random.randn(n_samples) * 0.5
# Fit Functional PLS
model = FunctionalPLS(m_max=10)
model.fit(X, y, ds=1.0)
# Predict
y_pred = model.predict(X, n_components=5)
# Evaluate
from fpls import compute_r2
r2 = compute_r2(y, y_pred)
print(f"R² = {r2:.3f}")
Adaptive Component Selection
from fpls import select_components
# Automatically select the optimal number of components
m_hat = select_components(X, y, m_max=10, tau=1.01, delta=0.1)
print(f"Selected {m_hat} components")
# Fit with selected components
model = FunctionalPLS(m_max=m_hat)
model.fit(X, y)
y_pred = model.predict(X)
Functional API (Research-Style)
For users familiar with the original replication code:
from fpls import fit_fpls
# Directly get coefficient array
coef, ds = fit_fpls(X, y, m_max=10, ds=1.0)
# coef has shape (n_features, m_max+1)
# coef[:, j] gives coefficients using j components
API Reference
Main Classes
FunctionalPLS(m_max=10, grid_size=None)
.fit(X, y, ds=None)- Fit the model.predict(X, n_components=None)- Make predictions.fit_predict(X, y, ds=None, n_components=None)- Fit and predict.coef_- Fitted coefficients (shape:n_features × (m_max+1))
Functions
fit_fpls(X, y, m_max=10, ds=None)
- Convenience function returning
(coef, ds)tuple
select_components(X, y, m_max=10, ds=None, tau=1.01, delta=0.1, xi=0.01)
- Adaptive early stopping to select optimal number of components
Utilities:
create_uniform_grid(start, end, n_points)- Create discretization gridcompute_mse(y_true, y_pred)- Mean squared errorcompute_r2(y_true, y_pred)- R-squaredcenter_functional_data(X)- Center by mean functionfrisch_waugh_residualize(Z, X_controls)- Residualize out controls
Examples
See the examples/ directory for complete worked examples, including:
- Basic functional regression
- Component selection
- Comparison with standard methods
Development
Run tests:
pytest
Run tests with coverage:
pytest --cov=fpls --cov-report=html
Citation
If you use this package in your research, please cite:
@article{babii2023functional,
title={Functional Partial Least-Squares: Adaptive Estimation and Inference},
author={Babii, Andrii and Carrasco, Marine and Tsafack, Idriss},
journal={Journal of the American Statistical Association},
year={2023}
}
License
MIT License - see LICENSE file for details.
Authors
- Andrii Babii
- Marine Carrasco
- Idriss Tsafack
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fpls-0.1.0.tar.gz.
File metadata
- Download URL: fpls-0.1.0.tar.gz
- Upload date:
- Size: 13.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b261f67dadbad5004198d8d01d17fdd17c1f14e3e9380f0304c3a77e66371d06
|
|
| MD5 |
eaf7fff0b4e01ec8f35a077bc10483f2
|
|
| BLAKE2b-256 |
47145ffb5223f0817f58a3c604830872fdeca39ea590d3f0795fca0e02f6d0f7
|
File details
Details for the file fpls-0.1.0-py3-none-any.whl.
File metadata
- Download URL: fpls-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8528861d46c79ae23713668462a7ea434087a87b75c64bd95b709aac78e4035a
|
|
| MD5 |
fb47ceef46d9c4c049d9da93c3372b8d
|
|
| BLAKE2b-256 |
eb04e37f2f4a6c62e8b9d2096ceaca5c30c4f668593f4d158d51a2a786f021a8
|