Skip to content
RgramCoverageSearchCV

CoverageSearchCV

See component workflows for rationale and worked analysis, the user guide for concepts, and result schemas for diagnostic tables.

rgram.CoverageSearchCV

[source]
class rgram.CoverageSearchCV(
    estimator,
    param_grid,
    *,
    cv=5,
    min_coverage=1.0,
    random_state=0,
)

Select parameters by validation MSE with explicit support requirements.

Parameters

estimator sklearn estimator

Cloneable single-feature regressor with fit and predict. Fit errors and prediction policies are respected, not overridden.

param_grid dict or list of dicts

Parameter names mapped to sequences of candidates, as in ParameterGrid. Nested names use the usual step__parameter convention.

cv int, splitter or iterable, default=5

Integer uses shuffled KFold. Otherwise supply a split(X, y, groups) object or iterable of nonempty, disjoint train/test index pairs.

min_coverage float, default=1.0

Minimum fraction of finite predictions required in every fold, in (0, 1]. Lowering this compares only supported rows and can favor selective models.

random_state int or None, default=0

Seed for integer-CV splitting. Does not reseed a supplied splitter.

Attributes

best_estimator_ estimator

Winning model refitted on all rows. Available only after successful fit.

best_params_ dict

Winning parameter combination.

best_index_ int

Position of the winner in cv_results_. Ties use the first candidate.

best_score_ float

Negative pooled unweighted validation MSE, not R-squared.

cv_results_ dict

Candidate parameters, MSE, support fractions, eligibility, selection loss, validation counts, and per-fold MSE/coverage arrays. See result schemas.

cv_splits_ tuple of (train_indices, test_indices)

Copies of the actual fold membership indices.

n_splits_ int

Number of supplied validation folds.

n_features_in_ int

Always one after successful fit.

feature_names_in_ ndarray of shape (1,)

Original feature name, only when the training input is named.

Notes

The selection loss pools squared errors over finite validation predictions. Each fold must independently meet min_coverage. Ineligible candidates have infinite selection loss. If none qualifies, fit raises and cv_results_ remains inspectable, but the search is not fitted. There is no n_jobs, scoring, refit, or error_score option. Inherited score reports R-squared. Weights affect fitting only. Direct weight forwarding to nested pipelines is not implemented. Unlike GridSearchCV's integer regression CV, integer CV here is shuffled. Preprocessing must be inside the candidate pipeline to avoid leakage.

Examples

>>> import numpy as np
>>> from rgram import CoverageSearchCV, Regressogram
>>> X = np.linspace(0, 1, 30).reshape(-1, 1)
>>> search = CoverageSearchCV(Regressogram(), {'n_bins': [1, 3]}, cv=3)
>>> _ = search.fit(X, X[:, 0])
>>> search.predict(X).shape
(30,)

Methods

Method Purpose
fit Evaluate candidates and refit the eligible winner on all observations.
get_metadata_routing Get metadata routing of this object.
get_params Get parameters for this estimator.
predict Predict through the refitted winning estimator.
score Return :ref:coefficient of determination <r2_score> on test data.
set_fit_request Configure whether metadata should be requested to be passed to the fit method.
set_params Set the parameters of this estimator.
set_score_request Configure whether metadata should be requested to be passed to the score method.

fit

[source]
rgram.CoverageSearchCV.fit(
    X,
    y,
    *,
    data=None,
    groups=None,
    sample_weight=None,
)

Evaluate candidates and refit the eligible winner on all observations.

Parameters

X array-like of shape (n_samples,) or (n_samples, 1), or str

Single feature or its column name when data is supplied.

y array-like or str

Aligned numeric response or its column name. Required.

data pandas.DataFrame, polars.DataFrame or polars.LazyFrame, default=None

Source for named feature and response columns.

groups array-like of shape (n_samples,) or None, default=None

Labels passed to an explicit group-aware splitter. Rejected with integer cv.

sample_weight array-like of shape (n_samples,) or None, default=None

Nonnegative fitting weights, sliced by training fold. Scoring is unweighted.

Returns

self CoverageSearchCV

Fitted search. The winner is refit on every supplied row.

Raises

ValueError

For invalid input, fold indices, policies, or when no candidate qualifies. Candidate fit/prediction errors propagate rather than becoming scores.

get_metadata_routing

[inherited API]
rgram.CoverageSearchCV.get_metadata_routing()

Get metadata routing of this object.

Please check metadata routing guide on how the routing mechanism works.

Returns

routing MetadataRequest

A sklearn.utils.metadata_routing.MetadataRequest encapsulating routing information.

get_params

[inherited API]
rgram.CoverageSearchCV.get_params(deep=True)

Get parameters for this estimator.

Parameters

deep bool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns

params dict

Parameter names mapped to their values.

predict

[source]
rgram.CoverageSearchCV.predict(X)

Predict through the refitted winning estimator.

Parameters

X array-like of shape (n_queries,) or (n_queries, 1)

Query feature values, with the fitted feature name if named.

Returns

prediction ndarray of shape (n_queries,)

Winner's predictions in query order, respecting its prediction policies.

Raises

sklearn.exceptions.NotFittedError

If a successful search has not produced best_estimator_.

score

[inherited API]
rgram.CoverageSearchCV.score(
    X,
    y,
    sample_weight=None,
)

Return coefficient of determination on test data.

The coefficient of determination, \(R^2\), is defined as \((1 - \frac{u}{v})\), where \(u\) is the residual sum of squares ((y_true - y_pred)** 2).sum() and \(v\) is the total sum of squares ((y_true - y_true.mean()) ** 2).sum(). The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a \(R^2\) score of 0.0.

Parameters

X array-like of shape (n_samples, n_features)

Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape (n_samples, n_samples_fitted), where n_samples_fitted is the number of samples used in the fitting for the estimator.

y array-like of shape (n_samples,) or (n_samples, n_outputs)

True values for X.

sample_weight array-like of shape (n_samples,), default=None

Sample weights.

Returns

score float

\(R^2\) of self.predict(X) w.r.t. y.

Notes

The \(R^2\) score used when calling score on a regressor uses multioutput='uniform_average' from version 0.23 to keep consistent with default value of sklearn.metrics.r2_score. This influences the score method of all the multioutput regressors (except for sklearn.multioutput.MultiOutputRegressor).

set_fit_request

[inherited API]
rgram.CoverageSearchCV.set_fit_request(
    *,
    data='$UNCHANGED$',
    groups='$UNCHANGED$',
    sample_weight='$UNCHANGED$',
)

Configure whether metadata should be requested to be passed to the fit method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a :term:meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config). Please check the metadata routing guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • 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.

Parameters

data str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for data parameter in fit.

groups str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for groups parameter in fit.

sample_weight str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in fit.

Returns

self object

The updated object.

set_params

[inherited API]
rgram.CoverageSearchCV.set_params(**params)

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as sklearn.pipeline.Pipeline). The latter have parameters of the form <component>__<parameter> so that it's possible to update each component of a nested object.

Parameters

**params dict

Estimator parameters.

Returns

self estimator instance

Estimator instance.

set_score_request

[inherited API]
rgram.CoverageSearchCV.set_score_request(*, sample_weight='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the score method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a :term:meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config). Please check the metadata routing guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • 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.

Parameters

sample_weight str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in score.

Returns

self object

The updated object.

Implementation source: model_selection.py.