pod.fit_all_robust_mean_models
fit_all_robust_mean_models(X, y, max_degree=10, n_folds=10)Fits all polynomial models (and optionally Kriging) and returns them for caching.
Instead of fitting models, selecting the best, and throwing the rest away, this function evaluates all candidates via k-fold Cross Validation (CV) and then fits every model to the full dataset. This allows the application to instantly swap between different model structures without recalculating.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| X | np.ndarray | 1D array or 2D matrix of input variable values. | required |
| y | np.ndarray | 1D array of outcome values (e.g., signal response). | required |
| max_degree | int | The maximum polynomial degree to test. Defaults to 10. | 10 |
| n_folds | int | Number of folds for Cross Validation. Defaults to 10. | 10 |
Returns
| Name | Type | Description |
|---|---|---|
| Tuple[Dict[Tuple[str, Any], Any], Dict[Tuple[str, Any], float], Tuple[str, Any]] | Tuple[Dict, Dict, Tuple]: - fitted_models: A dictionary mapping a key like ('Polynomial', 3) to the fully trained scikit-learn model. - cv_scores: A dictionary mapping the same keys to their Cross-Validation MSE scores. - cv_winner_key: The key of the model that achieved the lowest MSE. |
Examples
import numpy as np
X = np.linspace(0, 10, 50)
y = 3 * X + np.random.normal(0, 1, 50)
models, scores, best_key = fit_all_robust_mean_models(X, y)
print(f"The best model was: {best_key}")
# Instantly retrieve the degree-4 polynomial without refitting
poly_4 = models[('Polynomial', 4)]