TargetTransformer

class hcrystalball.preprocessing.TargetTransformer(estimator, y_transformer, omit_inverse_transformation=False)[source]

Bases: sklearn.base.TransformerMixin, sklearn.base.BaseEstimator

Enable transformation of the target.

Wrapper for applying an estimator to a transformed version of the target y and automatically transforming back predictions

Methods Summary

fit(X[, y])

Fit after reshaping and rescaling the target

fit_transform(X[, y])

Fit to data, then transform it.

get_params([deep])

Get parameters for this estimator.

named_steps()

Provide access to named steps for Pipeline

predict(X[, y])

Ensure correct estimator.predict with scaled target values

score(X[, y])

Ensures correct estimator.score with scaled target values

set_params(**params)

Set the parameters of this estimator.

transform(X[, y])

Transforms the features

Methods Documentation

fit(X, y=None)[source]

Fit after reshaping and rescaling the target

Reshape target to 2d, call fit_transform on 2d, return to 1d form and fit estimator on transformed target

Parameters
Returns

Fitted target transformer

Return type

TargetTransformer

fit_transform(X, y=None, **fit_params)

Fit to data, then transform it.

Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.

Parameters
  • X (array-like of shape (n_samples, n_features)) – Input samples.

  • y (array-like of shape (n_samples,) or (n_samples, n_outputs), default=None) – Target values (None for unsupervised transformations).

  • **fit_params (dict) – Additional fit parameters.

Returns

X_new – Transformed array.

Return type

ndarray array of shape (n_samples, n_features_new)

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

named_steps()[source]

Provide access to named steps for Pipeline

Returns

Dictionary of steps

Return type

dict

predict(X, y=None)[source]

Ensure correct estimator.predict with scaled target values

Parameters
Returns

Results of estimators prediction

Return type

pandas.DataFrame

score(X, y=None)[source]

Ensures correct estimator.score with scaled target values

Parameters
Returns

Results of estimators score function

Return type

Any

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, y=None)[source]

Transforms the features

Parameters
Returns

Result of estimator transform

Return type

numpy.ndarray