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 developed in:
Babii, A., Carrasco, M., & Tsafack, I. (2025). "Functional Partial Least-Squares: Adaptive Estimation and Inference." Journal of the American Statistical Association.
Overview
The fpls 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
- Support for both NumPy arrays and Pandas DataFrames
- Visualization tools for plotting coefficient functions
Installation
Install library:
pip install fpls
Quick Start
Example: Temperature Effects on Crop Yields
This example demonstrates FPLS on a real-world climate impact study. Using 70 years of county-level data east of 100th meridian, 1950–2020, we analyze how temperature exposure affects corn and soybean yields. The outcome variable is log-yield (bushels per acre), and the functional regressor is the distribution of temperature exposure during the crop growing season, measured in growing degree-days and discretized into 1°C temperature bins.
from fpls import load_example_data, fit_fpls, plot_coefficient_function
import matplotlib.pyplot as plt
# Load corn and soybean data
X_corn, y_corn, s = load_example_data("corn")
X_soy, y_soy, _ = load_example_data("soybeans")
# Fit FPLS models with 10 components
coef_corn, _ = fit_fpls(X_corn, y_corn, m_max=10, ds=1.0)
coef_soy, _ = fit_fpls(X_soy, y_soy, m_max=10, ds=1.0)
# Extract coefficients using m components
m = 4
beta_corn = coef_corn[:, m]
beta_soy = coef_soy[:, m]
Visualizing Results
# Create a figure with two subplots
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(12, 5))
# Plot corn on the first subplot
plot_coefficient_function(
s, beta_corn,
title="Impact of Temperature on Corn Yield",
xlabel="Temperature (°C)",
ylabel="Log Yield (Bushels)",
color="#2E86AB",
ax=ax1
)
# Plot soybeans on the second subplot
plot_coefficient_function(
s, beta_soy,
title="Impact of Temperature on Soybeans Yield",
xlabel="Temperature (°C)",
ylabel="Log Yield (Bushels)",
color="#E85D04",
ax=ax2
)
fig.savefig('docs/images/crop_yield_comparison.png', dpi=300, bbox_inches='tight')
plt.show()
Output:
The coefficient functions reveal how different temperature ranges affect crop yields, with the functional approach capturing nonlinearities of temperature effects at different parts of the distribution.
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
Visualization:
plot_coefficient_function(s, beta, ...)- Plot single coefficient functionplot_comparison(s_list, beta_list, titles, ...)- Compare multiple functionsload_example_data(dataset)- Load example datasets ('corn' or 'soybeans')
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 on simulated data
- Crop yield analysis
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={2025}
}
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.2.0.tar.gz.
File metadata
- Download URL: fpls-0.2.0.tar.gz
- Upload date:
- Size: 17.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf283fcdbe2c9e9f600b78efedce4b36599d06269937292c94023782afcd3bda
|
|
| MD5 |
3c60369bc663c548d1ca6fa3448d03ff
|
|
| BLAKE2b-256 |
e6d9e5f334481aa45f00e1535841ac46edde8c2ffebde87cb0489848a258b9ad
|
File details
Details for the file fpls-0.2.0-py3-none-any.whl.
File metadata
- Download URL: fpls-0.2.0-py3-none-any.whl
- Upload date:
- Size: 14.9 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 |
19e9d38a84ecceeadb2a23a05796e82f8acd988d5d2646a4318018ee2f12ffde
|
|
| MD5 |
14358ad9df1f84ee2de6c33ddd315316
|
|
| BLAKE2b-256 |
cc119892595d72912a54f93ee0ef47b5f1bdee42aca1281eb4730e1354ef44ec
|