Custom extensions of sklearn functionalities

Custom expansions of sklearn functionalities.

Note

This module provides custom expansions of some sklearn classes and functions which are necessary to fit the purposes for the desired functionalities of the MLR module. As long-term goal we would like to include these functionalities to the sklearn package since we believe these additions might be helpful for everyone. This module serves as interim solution. To ensure that all features are properly working this module is also covered by tests, which will also be expanded in the future.

Classes

AdvancedPipeline(*args, **kwargs)

Expand sklearn.pipeline.Pipeline.

AdvancedRFE(*args, **kwargs)

Expand sklearn.feature_selection.RFE.

AdvancedRFECV(*args, **kwargs)

Expand sklearn.feature_selection.RFECV.

AdvancedTransformedTargetRegressor(*args, …)

Expand sklearn.compose.TransformedTargetRegressor.

FeatureSelectionTransformer(*args, **kwargs)

Transformer step of a feature selection estimator.

Functions

cross_val_score_weighted(estimator, x_data)

Expand sklearn.model_selection.cross_val_score().

get_rfecv_transformer(rfecv_estimator)

Get transformer step of RFECV estimator.

perform_efecv(estimator, x_data, y_data, …)

Perform exhaustive feature selection.

class esmvaltool.diag_scripts.mlr.custom_sklearn.AdvancedPipeline(*args: Any, **kwargs: Any)[source]

Bases: sklearn.pipeline.

Expand sklearn.pipeline.Pipeline.

Attributes

coef_

Model coefficients.

feature_importances_

Feature importances.

Methods

fit_target_transformer_only(y_data, **fit_kwargs)

Fit only transform step of of target regressor.

fit_transformers_only(x_data, y_data, …)

Fit only transform steps of Pipeline.

transform_only(x_data)

Only perform transform steps of Pipeline.

transform_target_only(y_data)

Only perform transform steps of target regressor.

property coef_

Model coefficients.

Type

numpy.ndarray

property feature_importances_

Feature importances.

Type

numpy.ndarray

fit_target_transformer_only(y_data, **fit_kwargs)[source]

Fit only transform step of of target regressor.

fit_transformers_only(x_data, y_data, **fit_kwargs)[source]

Fit only transform steps of Pipeline.

transform_only(x_data)[source]

Only perform transform steps of Pipeline.

transform_target_only(y_data)[source]

Only perform transform steps of target regressor.

class esmvaltool.diag_scripts.mlr.custom_sklearn.AdvancedRFE(*args: Any, **kwargs: Any)[source]

Bases: sklearn.feature_selection.

Expand sklearn.feature_selection.RFE.

Methods

fit(x_data, y_data, **fit_kwargs)

Expand fit() to accept kwargs.

predict(x_data, **predict_kwargs)

Expand predict() to accept kwargs.

fit(x_data, y_data, **fit_kwargs)[source]

Expand fit() to accept kwargs.

predict(x_data, **predict_kwargs)

Expand predict() to accept kwargs.

class esmvaltool.diag_scripts.mlr.custom_sklearn.AdvancedRFECV(*args: Any, **kwargs: Any)[source]

Bases: sklearn.feature_selection.

Expand sklearn.feature_selection.RFECV.

Methods

fit(x_data, y_data[, groups])

Expand fit() to accept kwargs.

predict(x_data, **predict_kwargs)

Expand predict() to accept kwargs.

fit(x_data, y_data, groups=None, **fit_kwargs)[source]

Expand fit() to accept kwargs.

predict(x_data, **predict_kwargs)

Expand predict() to accept kwargs.

class esmvaltool.diag_scripts.mlr.custom_sklearn.AdvancedTransformedTargetRegressor(*args: Any, **kwargs: Any)[source]

Bases: sklearn.compose.

Expand sklearn.compose.TransformedTargetRegressor.

Attributes

coef_

Model coefficients.

feature_importances_

Feature importances.

Methods

fit(x_data, y_data, **fit_kwargs)

Expand fit() to accept kwargs.

fit_transformer_only(y_data, **fit_kwargs)

Fit only transformer step.

predict(x_data[, always_return_1d])

Expand predict() to accept kwargs.

property coef_

Model coefficients.

Type

numpy.ndarray

property feature_importances_

Feature importances.

Type

numpy.ndarray

fit(x_data, y_data, **fit_kwargs)[source]

Expand fit() to accept kwargs.

fit_transformer_only(y_data, **fit_kwargs)[source]

Fit only transformer step.

predict(x_data, always_return_1d=True, **predict_kwargs)[source]

Expand predict() to accept kwargs.

class esmvaltool.diag_scripts.mlr.custom_sklearn.FeatureSelectionTransformer(*args: Any, **kwargs: Any)[source]

Bases: sklearn.base., sklearn.feature_selection._base.

Transformer step of a feature selection estimator.

Methods

fit(*_, **__)

Empty method.

fit(*_, **__)[source]

Empty method.

esmvaltool.diag_scripts.mlr.custom_sklearn.cross_val_score_weighted(estimator, x_data, y_data=None, groups=None, scoring=None, cv=None, n_jobs=None, verbose=0, fit_params=None, pre_dispatch='2*n_jobs', error_score=nan, sample_weights=None)[source]

Expand sklearn.model_selection.cross_val_score().

esmvaltool.diag_scripts.mlr.custom_sklearn.get_rfecv_transformer(rfecv_estimator)[source]

Get transformer step of RFECV estimator.

esmvaltool.diag_scripts.mlr.custom_sklearn.perform_efecv(estimator, x_data, y_data, **kwargs)[source]

Perform exhaustive feature selection.