DocumentationClassesTransformedTargetRegressor

Class: TransformedTargetRegressor

Meta-estimator to regress on a transformed target.

Useful for applying a non-linear transformation to the target y in regression problems. This transformation can be given as a Transformer such as the QuantileTransformer or as a function and its inverse such as np.log and np.exp.

The computation during fit is:

Python Reference

Constructors

new TransformedTargetRegressor()

new TransformedTargetRegressor(opts?): TransformedTargetRegressor

Parameters

ParameterTypeDescription
opts?object-
opts.check_inverse?booleanWhether to check that transform followed by inverse_transform or func followed by inverse_func leads to the original targets.
opts.func?anyFunction to apply to y before passing to fit. Cannot be set at the same time as transformer. If func is None, the function used will be the identity function. If func is set, inverse_func also needs to be provided. The function needs to return a 2-dimensional array.
opts.inverse_func?anyFunction to apply to the prediction of the regressor. Cannot be set at the same time as transformer. The inverse function is used to return predictions to the same space of the original training labels. If inverse_func is set, func also needs to be provided. The inverse function needs to return a 2-dimensional array.
opts.regressor?anyRegressor object such as derived from RegressorMixin. This regressor will automatically be cloned each time prior to fitting. If regressor is None, LinearRegression is created and used.
opts.transformer?anyEstimator object such as derived from TransformerMixin. Cannot be set at the same time as func and inverse_func. If transformer is None as well as func and inverse_func, the transformer will be an identity transformer. Note that the transformer will be cloned during fitting. Also, the transformer is restricting y to be a numpy array.

Returns TransformedTargetRegressor

Defined in generated/compose/TransformedTargetRegressor.ts:25

Properties

PropertyTypeDefault valueDefined in
_isDisposedbooleanfalsegenerated/compose/TransformedTargetRegressor.ts:23
_isInitializedbooleanfalsegenerated/compose/TransformedTargetRegressor.ts:22
_pyPythonBridgeundefinedgenerated/compose/TransformedTargetRegressor.ts:21
idstringundefinedgenerated/compose/TransformedTargetRegressor.ts:18
optsanyundefinedgenerated/compose/TransformedTargetRegressor.ts:19

Accessors

feature_names_in_

Get Signature

get feature_names_in_(): Promise<ArrayLike>

Names of features seen during fit. Defined only when X has feature names that are all strings.

Returns Promise<ArrayLike>

Defined in generated/compose/TransformedTargetRegressor.ts:393


py

Get Signature

get py(): PythonBridge

Returns PythonBridge

Set Signature

set py(pythonBridge): void

Parameters

ParameterType
pythonBridgePythonBridge

Returns void

Defined in generated/compose/TransformedTargetRegressor.ts:57


regressor_

Get Signature

get regressor_(): Promise<any>

Fitted regressor.

Returns Promise<any>

Defined in generated/compose/TransformedTargetRegressor.ts:339


transformer_

Get Signature

get transformer_(): Promise<any>

Transformer used in fit and predict.

Returns Promise<any>

Defined in generated/compose/TransformedTargetRegressor.ts:366

Methods

dispose()

dispose(): Promise<void>

Disposes of the underlying Python resources.

Once dispose() is called, the instance is no longer usable.

Returns Promise<void>

Defined in generated/compose/TransformedTargetRegressor.ts:113


fit()

fit(opts): Promise<any>

Fit the model according to the given training data.

Parameters

ParameterTypeDescription
optsobject-
opts.fit_params?anyParameters passed to the fit method of the underlying regressor.
opts.X?ArrayLikeTraining vector, where n_samples is the number of samples and n_features is the number of features.
opts.y?ArrayLikeTarget values.

Returns Promise<any>

Defined in generated/compose/TransformedTargetRegressor.ts:130


get_metadata_routing()

get_metadata_routing(opts): Promise<any>

Raise NotImplementedError.

This estimator does not support metadata routing yet.

Parameters

ParameterType
optsobject

Returns Promise<any>

Defined in generated/compose/TransformedTargetRegressor.ts:178


init()

init(py): Promise<void>

Initializes the underlying Python resources.

This instance is not usable until the Promise returned by init() resolves.

Parameters

ParameterType
pyPythonBridge

Returns Promise<void>

Defined in generated/compose/TransformedTargetRegressor.ts:70


predict()

predict(opts): Promise<ArrayLike>

Predict using the base regressor, applying inverse.

The regressor is used to predict and the inverse_func or inverse_transform is applied before returning the prediction.

Parameters

ParameterTypeDescription
optsobject-
opts.predict_params?anyParameters passed to the predict method of the underlying regressor.
opts.X?ArrayLikeSamples.

Returns Promise<ArrayLike>

Defined in generated/compose/TransformedTargetRegressor.ts:210


score()

score(opts): Promise<number>

Return the coefficient of determination of the prediction.

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

ParameterTypeDescription
optsobject-
opts.sample_weight?ArrayLikeSample weights.
opts.X?ArrayLike[]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.
opts.y?ArrayLikeTrue values for X.

Returns Promise<number>

Defined in generated/compose/TransformedTargetRegressor.ts:253


set_score_request()

set_score_request(opts): Promise<any>

Request metadata passed to the score 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:

Parameters

ParameterTypeDescription
optsobject-
opts.sample_weight?string | booleanMetadata routing for sample_weight parameter in score.

Returns Promise<any>

Defined in generated/compose/TransformedTargetRegressor.ts:303