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 (opens in a new tab)
Constructors
constructor()
Signature
new TransformedTargetRegressor(opts?: object): TransformedTargetRegressor;
Parameters
Name | Type | Description |
---|---|---|
opts? | object | - |
opts.check_inverse? | boolean | Whether to check that transform followed by inverse\_transform or func followed by inverse\_func leads to the original targets. Default Value true |
opts.func? | any | Function to apply to y before passing to fit . Cannot be set at the same time as transformer . The function needs to return a 2-dimensional array. If func is None , the function used will be the identity function. |
opts.inverse_func? | any | Function to apply to the prediction of the regressor. Cannot be set at the same time as transformer . The function needs to return a 2-dimensional array. The inverse function is used to return predictions to the same space of the original training labels. |
opts.regressor? | any | Regressor 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? | any | Estimator 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
Defined in: generated/compose/TransformedTargetRegressor.ts:25 (opens in a new tab)
Properties
_isDisposed
boolean
=false
Defined in: generated/compose/TransformedTargetRegressor.ts:23 (opens in a new tab)
_isInitialized
boolean
=false
Defined in: generated/compose/TransformedTargetRegressor.ts:22 (opens in a new tab)
_py
PythonBridge
Defined in: generated/compose/TransformedTargetRegressor.ts:21 (opens in a new tab)
id
string
Defined in: generated/compose/TransformedTargetRegressor.ts:18 (opens in a new tab)
opts
any
Defined in: generated/compose/TransformedTargetRegressor.ts:19 (opens in a new tab)
Accessors
feature_names_in_
Names of features seen during fit. Defined only when X
has feature names that are all strings.
Signature
feature_names_in_(): Promise<ArrayLike>;
Returns
Promise
<ArrayLike
>
Defined in: generated/compose/TransformedTargetRegressor.ts:339 (opens in a new tab)
py
Signature
py(): PythonBridge;
Returns
PythonBridge
Defined in: generated/compose/TransformedTargetRegressor.ts:57 (opens in a new tab)
Signature
py(pythonBridge: PythonBridge): void;
Parameters
Name | Type |
---|---|
pythonBridge | PythonBridge |
Returns
void
Defined in: generated/compose/TransformedTargetRegressor.ts:61 (opens in a new tab)
regressor_
Fitted regressor.
Signature
regressor_(): Promise<any>;
Returns
Promise
<any
>
Defined in: generated/compose/TransformedTargetRegressor.ts:285 (opens in a new tab)
transformer_
Transformer used in fit
and predict
.
Signature
transformer_(): Promise<any>;
Returns
Promise
<any
>
Defined in: generated/compose/TransformedTargetRegressor.ts:312 (opens in a new tab)
Methods
dispose()
Disposes of the underlying Python resources.
Once dispose()
is called, the instance is no longer usable.
Signature
dispose(): Promise<void>;
Returns
Promise
<void
>
Defined in: generated/compose/TransformedTargetRegressor.ts:118 (opens in a new tab)
fit()
Fit the model according to the given training data.
Signature
fit(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike | Training vector, where n\_samples is the number of samples and n\_features is the number of features. |
opts.fit_params? | any | Parameters passed to the fit method of the underlying regressor. |
opts.y? | ArrayLike | Target values. |
Returns
Promise
<any
>
Defined in: generated/compose/TransformedTargetRegressor.ts:135 (opens in a new tab)
init()
Initializes the underlying Python resources.
This instance is not usable until the Promise
returned by init()
resolves.
Signature
init(py: PythonBridge): Promise<void>;
Parameters
Name | Type |
---|---|
py | PythonBridge |
Returns
Promise
<void
>
Defined in: generated/compose/TransformedTargetRegressor.ts:70 (opens in a new tab)
predict()
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.
Signature
predict(opts: object): Promise<ArrayLike>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike | Samples. |
opts.predict_params? | any | Parameters passed to the predict method of the underlying regressor. |
Returns
Promise
<ArrayLike
>
Defined in: generated/compose/TransformedTargetRegressor.ts:188 (opens in a new tab)
score()
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.
Signature
score(opts: object): Promise<number>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
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.sample_weight? | ArrayLike | Sample weights. |
opts.y? | ArrayLike | True values for X . |
Returns
Promise
<number
>
Defined in: generated/compose/TransformedTargetRegressor.ts:234 (opens in a new tab)