CoverageSearchCV¶
See component workflows for rationale and worked analysis, the user guide for concepts, and result schemas for diagnostic tables.
rgram.CoverageSearchCV¶
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¶
estimatorsklearn estimatorCloneable single-feature regressor with fit and predict. Fit errors and prediction policies are respected, not overridden.
param_griddict or list of dictsParameter names mapped to sequences of candidates, as in ParameterGrid. Nested names use the usual step__parameter convention.
cvint, splitter or iterable, default=5Integer uses shuffled KFold. Otherwise supply a split(X, y, groups) object or iterable of nonempty, disjoint train/test index pairs.
min_coveragefloat, default=1.0Minimum fraction of finite predictions required in every fold, in (0, 1]. Lowering this compares only supported rows and can favor selective models.
random_stateint or None, default=0Seed for integer-CV splitting. Does not reseed a supplied splitter.
Attributes¶
best_estimator_estimatorWinning model refitted on all rows. Available only after successful fit.
best_params_dictWinning parameter combination.
best_index_intPosition of the winner in
cv_results_. Ties use the first candidate.best_score_floatNegative pooled unweighted validation MSE, not R-squared.
cv_results_dictCandidate 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_intNumber of supplied validation folds.
n_features_in_intAlways 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¶
rgram.CoverageSearchCV.fit(
X,
y,
*,
data=None,
groups=None,
sample_weight=None,
)Evaluate candidates and refit the eligible winner on all observations.
Parameters¶
Xarray-like of shape (n_samples,) or (n_samples, 1), or strSingle feature or its column name when data is supplied.
yarray-like or strAligned numeric response or its column name. Required.
datapandas.DataFrame, polars.DataFrame or polars.LazyFrame, default=NoneSource for named feature and response columns.
groupsarray-like of shape (n_samples,) or None, default=NoneLabels passed to an explicit group-aware splitter. Rejected with integer cv.
sample_weightarray-like of shape (n_samples,) or None, default=NoneNonnegative fitting weights, sliced by training fold. Scoring is unweighted.
Returns¶
selfCoverageSearchCVFitted search. The winner is refit on every supplied row.
Raises¶
ValueErrorFor invalid input, fold indices, policies, or when no candidate qualifies. Candidate fit/prediction errors propagate rather than becoming scores.
get_metadata_routing¶
rgram.CoverageSearchCV.get_metadata_routing()Get metadata routing of this object.
Please check metadata routing guide on how the routing mechanism works.
Returns¶
routingMetadataRequestA
sklearn.utils.metadata_routing.MetadataRequestencapsulating routing information.
get_params¶
rgram.CoverageSearchCV.get_params(deep=True)Get parameters for this estimator.
Parameters¶
deepbool, default=TrueIf True, will return the parameters for this estimator and contained subobjects that are estimators.
Returns¶
paramsdictParameter names mapped to their values.
predict¶
rgram.CoverageSearchCV.predict(X)Predict through the refitted winning estimator.
Parameters¶
Xarray-like of shape (n_queries,) or (n_queries, 1)Query feature values, with the fitted feature name if named.
Returns¶
predictionndarray of shape (n_queries,)Winner's predictions in query order, respecting its prediction policies.
Raises¶
sklearn.exceptions.NotFittedErrorIf a successful search has not produced
best_estimator_.
score¶
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¶
Xarray-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), wheren_samples_fittedis the number of samples used in the fitting for the estimator.yarray-like of shape (n_samples,) or (n_samples, n_outputs)True values for
X.sample_weightarray-like of shape (n_samples,), default=NoneSample weights.
Returns¶
scorefloat\(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¶
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 tofitif provided. The request is ignored if metadata is not provided. -
False: metadata is not requested and the meta-estimator will not pass it tofit. -
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¶
datastr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGEDMetadata routing for
dataparameter infit.groupsstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGEDMetadata routing for
groupsparameter infit.sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGEDMetadata routing for
sample_weightparameter infit.
Returns¶
selfobjectThe updated object.
set_params¶
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¶
**paramsdictEstimator parameters.
Returns¶
selfestimator instanceEstimator instance.
set_score_request¶
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 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.
Parameters¶
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGEDMetadata routing for
sample_weightparameter inscore.
Returns¶
selfobjectThe updated object.
Implementation source: model_selection.py.