Class: RobustScaler
Scale features using statistics that are robust to outliers.
This Scaler removes the median and scales the data according to the quantile range (defaults to IQR: Interquartile Range). The IQR is the range between the 1st quartile (25th quantile) and the 3rd quartile (75th quantile).
Centering and scaling happen independently on each feature by computing the relevant statistics on the samples in the training set. Median and interquartile range are then stored to be used on later data using the transform
method.
Standardization of a dataset is a common preprocessing for many machine learning estimators. Typically this is done by removing the mean and scaling to unit variance. However, outliers can often influence the sample mean / variance in a negative way. In such cases, using the median and the interquartile range often give better results. For an example visualization and comparison to other scalers, refer to Compare RobustScaler with other scalers.
Constructors
new RobustScaler()
new RobustScaler(
opts
?):RobustScaler
Parameters
Parameter | Type | Description |
---|---|---|
opts ? | object | - |
opts.copy ? | boolean | If false , try to avoid a copy and do inplace scaling instead. This is not guaranteed to always work inplace; e.g. if the data is not a NumPy array or scipy.sparse CSR matrix, a copy may still be returned. |
opts.quantile_range ? | any | Quantile range used to calculate scale_ . By default this is equal to the IQR, i.e., q_min is the first quantile and q_max is the third quantile. |
opts.unit_variance ? | boolean | If true , scale data so that normally distributed features have a variance of 1. In general, if the difference between the x-values of q_max and q_min for a standard normal distribution is greater than 1, the dataset will be scaled down. If less than 1, the dataset will be scaled up. |
opts.with_centering ? | boolean | If true , center the data before scaling. This will cause transform to raise an exception when attempted on sparse matrices, because centering them entails building a dense matrix which in common use cases is likely to be too large to fit in memory. |
opts.with_scaling ? | boolean | If true , scale the data to interquartile range. |
Returns RobustScaler
Defined in generated/preprocessing/RobustScaler.ts:27
Properties
Property | Type | Default value | Defined in |
---|---|---|---|
_isDisposed | boolean | false | generated/preprocessing/RobustScaler.ts:25 |
_isInitialized | boolean | false | generated/preprocessing/RobustScaler.ts:24 |
_py | PythonBridge | undefined | generated/preprocessing/RobustScaler.ts:23 |
id | string | undefined | generated/preprocessing/RobustScaler.ts:20 |
opts | any | undefined | generated/preprocessing/RobustScaler.ts:21 |
Accessors
center_
Get Signature
get center_():
Promise
<any
>
The median value for each feature in the training set.
Returns Promise
<any
>
Defined in generated/preprocessing/RobustScaler.ts:385
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/preprocessing/RobustScaler.ts:456
n_features_in_
Get Signature
get n_features_in_():
Promise
<number
>
Number of features seen during fit.
Returns Promise
<number
>
Defined in generated/preprocessing/RobustScaler.ts:431
py
Get Signature
get py():
PythonBridge
Returns PythonBridge
Set Signature
set py(
pythonBridge
):void
Parameters
Parameter | Type |
---|---|
pythonBridge | PythonBridge |
Returns void
Defined in generated/preprocessing/RobustScaler.ts:65
scale_
Get Signature
get scale_():
Promise
<any
>
The (scaled) interquartile range for each feature in the training set.
Returns Promise
<any
>
Defined in generated/preprocessing/RobustScaler.ts:408
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/preprocessing/RobustScaler.ts:117
fit()
fit(
opts
):Promise
<any
>
Compute the median and quantiles to be used for scaling.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike | The data used to compute the median and quantiles used for later scaling along the features axis. |
opts.y ? | any | Not used, present here for API consistency by convention. |
Returns Promise
<any
>
Defined in generated/preprocessing/RobustScaler.ts:134
fit_transform()
fit_transform(
opts
):Promise
<any
[]>
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
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.fit_params ? | any | Additional fit parameters. |
opts.X ? | ArrayLike [] | Input samples. |
opts.y ? | ArrayLike | Target values (undefined for unsupervised transformations). |
Returns Promise
<any
[]>
Defined in generated/preprocessing/RobustScaler.ts:173
get_feature_names_out()
get_feature_names_out(
opts
):Promise
<any
>
Get output feature names for transformation.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.input_features ? | any | Input features. |
Returns Promise
<any
>
Defined in generated/preprocessing/RobustScaler.ts:215
get_metadata_routing()
get_metadata_routing(
opts
):Promise
<any
>
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.routing ? | any | A MetadataRequest encapsulating routing information. |
Returns Promise
<any
>
Defined in generated/preprocessing/RobustScaler.ts:251
init()
init(
py
):Promise
<void
>
Initializes the underlying Python resources.
This instance is not usable until the Promise
returned by init()
resolves.
Parameters
Parameter | Type |
---|---|
py | PythonBridge |
Returns Promise
<void
>
Defined in generated/preprocessing/RobustScaler.ts:78
inverse_transform()
inverse_transform(
opts
):Promise
<ArrayLike
>
Scale back the data to the original representation.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike | The rescaled data to be transformed back. |
Returns Promise
<ArrayLike
>
Defined in generated/preprocessing/RobustScaler.ts:285
set_output()
set_output(
opts
):Promise
<any
>
Set output container.
See Introducing the set_output API for an example on how to use the API.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.transform ? | "default" | "pandas" | "polars" | Configure output of transform and fit_transform . |
Returns Promise
<any
>
Defined in generated/preprocessing/RobustScaler.ts:321
transform()
transform(
opts
):Promise
<ArrayLike
>
Center and scale the data.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike | The data used to scale along the specified axis. |
Returns Promise
<ArrayLike
>
Defined in generated/preprocessing/RobustScaler.ts:353