nirs4all.operators.models.sklearn.tabpfn_nirs module
TabPFN NIRS regressor with a fixed, empirically-validated preprocessing.
This module provides TabPFNNIRSRegressor, a sklearn-compatible NIRS
regressor that pairs a fixed preprocessing chain with the TabPFN tabular
foundation model. The recipe avoids per-dataset HPO entirely.
Recipe
SG(window_length=11, polyorder=2, deriv=1) ▶ OSC() ▶
centering (with_std=False) ▶ TabPFNRegressor(n_estimators=16).
If the post-OSC matrix has more than max_features columns, an evenly
spaced linspace subsample brings it back below the TabPFN v3 hard limit
of 2000 features.
Empirical results on a 57-dataset NIRS cohort (regression, paper splits)
versus the TabPFN paper’s 72-chain per-dataset HPO (TabPFN_opt):
median RMSE delta: ~+2.5%
worst case: +47% on one dataset (Brix_spxy70 at n=35)
~21 of 57 datasets beat
TabPFN_optoutright
Cost is a single TabPFN training per dataset (no HPO, no stacking, no CV
selector). The recipe was chosen by extracting the most-frequent winning
preprocessing motif from the TabPFN paper logs (deriv-1 SG with OSC
correction) and a small n_estimators sweep (4/8/16/32) that pinned
n_estimators=16 as the sweet spot.
Requirements
tabpfn(pip install tabpfn). Imported lazily insidefit(), so importing this module does not require the optional dependency.
- class nirs4all.operators.models.sklearn.tabpfn_nirs.TabPFNNIRSRegressor(n_estimators: int = 16, max_features: int = 2000, sg_window_length: int = 11, sg_polyorder: int = 2, sg_deriv: int = 1, osc_n_components: int = 1, random_state: int = 0, device: str = 'auto', model_path: str = 'auto')[source]
Bases:
RegressorMixin,BaseEstimatorNIRS-tuned TabPFN regressor with a fixed AGG preprocessing pipeline.
- Parameters:
n_estimators (int, default=16) – TabPFN ensemble size at final fit. Selected empirically.
max_features (int, default=2000) – TabPFN v3 hard limit on input features. If the preprocessed matrix exceeds it, columns are uniformly subsampled via
np.linspace.sg_window_length (int, default=11)
sg_polyorder (int, default=2)
sg_deriv (int, default=1) – Savitzky-Golay smoothing parameters.
osc_n_components (int, default=1) – Number of orthogonal-signal-correction components to remove.
random_state (int, default=0) – Random seed for TabPFN.
device (str, default="auto") – TabPFN device.
"auto","cpu", or"cuda".model_path (str, default="auto") – TabPFN checkpoint path.
"auto"loads the default v3 checkpoint.
- Variables:
sg (SavitzkyGolay) – Fitted SG transformer.
osc (OSC) – Fitted OSC transformer.
scaler (StandardScaler) – Fitted centering scaler.
model (TabPFNRegressor) – Fitted TabPFN model.
n_features_in (int) – Number of features seen at fit time.
n_features_used (int) – Number of features actually fed to TabPFN (after subsample cap).
subsample_idx (ndarray or None) – Column indices used.
Nonewhen no subsample was applied.
Notes
On a 57-dataset NIRS cohort (paper splits) the fixed recipe lands at median RMSE ~+2.5% versus TabPFN_opt’s 72-chain HPO and beats it on ~37% of datasets, at a single TabPFN training per dataset.
The recipe is intentionally fixed. For per-dataset preprocessing selection, run an external CV loop over candidate chains and feed the chosen ones into this class.
Examples
>>> from nirs4all.operators.models import TabPFNNIRSRegressor >>> est = TabPFNNIRSRegressor(n_estimators=16) >>> est.fit(X_train, y_train) >>> y_pred = est.predict(X_test)
- fit(X: ndarray, y: ndarray) TabPFNNIRSRegressor[source]
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') TabPFNNIRSRegressor
Configure whether metadata should be requested to be passed to the
scoremethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.