pod.fit_robust_mean_model

fit_robust_mean_model(
    X,
    y,
    max_degree=10,
    n_folds=10,
    model_override='auto',
    force_degree=None,
)

Fits regression models (Polynomials and Kriging) and selects the optimal one.

This function performs k-fold Cross Validation (CV) to find the model type (Polynomial or Kriging) and parameters (e.g., degree) that minimize the Mean Squared Error (MSE), balancing bias and variance.

When model_override is set to "polynomial" or "kriging", CV selection is skipped and the requested model type is fitted directly.

Parameters

Name Type Description Default
X np.ndarray 1D array of input variable values (e.g., flaw size). 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
model_override str Force a model type. One of "auto", "polynomial", or "kriging". Defaults to "auto". 'auto'
force_degree int | None When model_override="polynomial", use this degree instead of CV selection. Defaults to None (CV selects). None

Returns

Name Type Description
Any Any A fitted scikit-learn model with the following added attributes:
Any - model_type_ (str): Either ‘Polynomial’ or ‘Kriging’.
Any - model_params_ (Any): The selected integer degree or the fitted kernel.
Any - cv_scores_ (dict): The cross-validation MSE scores for all tested models.

Examples

import numpy as np
X = np.linspace(0, 10, 50)
y = 3 * X + np.random.normal(0, 1, 50)
model = fit_robust_mean_model(X, y)
print(model.model_type_)

# Force a cubic polynomial
model = fit_robust_mean_model(X, y, model_override="polynomial", force_degree=3)