cca_zoo.model_selection.GridSearchCV#

class cca_zoo.model_selection.GridSearchCV(estimator, param_grid, *, scoring=None, n_jobs=None, refit=True, cv=None, verbose=0, pre_dispatch='2*n_jobs', error_score=nan, return_train_score=False)[source]#

Bases: GridSearchCV, BaseSearchCV

decision_function(X)#

Call decision_function on the estimator with the best found parameters.

Only available if refit=True and the underlying estimator supports decision_function.

Parameters:

X (indexable, length n_samples) – Must fulfill the input assumptions of the underlying estimator.

Returns:

y_score – Result of the decision function for X based on the estimator with the best found parameters.

Return type:

ndarray of shape (n_samples,) or (n_samples, n_classes) or (n_samples, n_classes * (n_classes-1) / 2)

fit(views, y=None, *, groups=None, **fit_params)#

Run fit with all sets of parameters.

Parameters:
  • X (array-like of shape (n_samples, n_features)) – Training vector, where n_samples is the number of samples and n_features is the number of features.

  • y (array-like of shape (n_samples, n_output) or (n_samples,), default=None) – Target relative to X for classification or regression; None for unsupervised learning.

  • groups (array-like of shape (n_samples,), default=None) – Group labels for the samples used while splitting the dataset into train/test set. Only used in conjunction with a “Group” cv instance (e.g., GroupKFold).

  • **fit_params (dict of str -> object) –

    Parameters passed to the fit method of the estimator.

    If a fit parameter is an array-like whose length is equal to num_samples then it will be split across CV groups along with X and y. For example, the sample_weight parameter is split because len(sample_weights) = len(X).

Returns:

self – Instance of fitted estimator.

Return type:

object

get_metadata_routing()#

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:

routing – A MetadataRequest encapsulating routing information.

Return type:

MetadataRequest

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 – Parameter names mapped to their values.

Return type:

dict

inverse_transform(Xt)#

Call inverse_transform on the estimator with the best found params.

Only available if the underlying estimator implements inverse_transform and refit=True.

Parameters:

Xt (indexable, length n_samples) – Must fulfill the input assumptions of the underlying estimator.

Returns:

X – Result of the inverse_transform function for Xt based on the estimator with the best found parameters.

Return type:

{ndarray, sparse matrix} of shape (n_samples, n_features)

predict(X)#

Call predict on the estimator with the best found parameters.

Only available if refit=True and the underlying estimator supports predict.

Parameters:

X (indexable, length n_samples) – Must fulfill the input assumptions of the underlying estimator.

Returns:

y_pred – The predicted labels or values for X based on the estimator with the best found parameters.

Return type:

ndarray of shape (n_samples,)

predict_log_proba(X)#

Call predict_log_proba on the estimator with the best found parameters.

Only available if refit=True and the underlying estimator supports predict_log_proba.

Parameters:

X (indexable, length n_samples) – Must fulfill the input assumptions of the underlying estimator.

Returns:

y_pred – Predicted class log-probabilities for X based on the estimator with the best found parameters. The order of the classes corresponds to that in the fitted attribute classes_.

Return type:

ndarray of shape (n_samples,) or (n_samples, n_classes)

predict_proba(X)#

Call predict_proba on the estimator with the best found parameters.

Only available if refit=True and the underlying estimator supports predict_proba.

Parameters:

X (indexable, length n_samples) – Must fulfill the input assumptions of the underlying estimator.

Returns:

y_pred – Predicted class probabilities for X based on the estimator with the best found parameters. The order of the classes corresponds to that in the fitted attribute classes_.

Return type:

ndarray of shape (n_samples,) or (n_samples, n_classes)

score(X, y=None)#

Return the score on the given data, if the estimator has been refit.

This uses the score defined by scoring where provided, and the best_estimator_.score method otherwise.

Parameters:
  • X (array-like of shape (n_samples, n_features)) – Input data, where n_samples is the number of samples and n_features is the number of features.

  • y (array-like of shape (n_samples, n_output) or (n_samples,), default=None) – Target relative to X for classification or regression; None for unsupervised learning.

Returns:

score – The score defined by scoring if provided, and the best_estimator_.score method otherwise.

Return type:

float

score_samples(X)#

Call score_samples on the estimator with the best found parameters.

Only available if refit=True and the underlying estimator supports score_samples.

New in version 0.24.

Parameters:

X (iterable) – Data to predict on. Must fulfill input requirements of the underlying estimator.

Returns:

y_score – The best_estimator_.score_samples method.

Return type:

ndarray of shape (n_samples,)

set_fit_request(*, groups: bool | None | str = '$UNCHANGED$', views: bool | None | str = '$UNCHANGED$') GridSearchCV#

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User 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.

New in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
  • groups (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for groups parameter in fit.

  • views (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for views parameter in fit.

Returns:

self – The updated object.

Return type:

object

set_params(**params)#

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as 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.

Return type:

estimator instance

transform(X)#

Call transform on the estimator with the best found parameters.

Only available if the underlying estimator supports transform and refit=True.

Parameters:

X (indexable, length n_samples) – Must fulfill the input assumptions of the underlying estimator.

Returns:

XtX transformed in the new space based on the estimator with the best found parameters.

Return type:

{ndarray, sparse matrix} of shape (n_samples, n_features)

property classes_#

Class labels.

Only available when refit=True and the estimator is a classifier.

property n_features_in_#

Number of features seen during fit.

Only available when refit=True.