StandardScaler
Standardize features by removing the mean and scaling to unit variance.
The standard score of a sample x
is calculated as:
Python Reference (opens in a new tab)
Constructors
constructor()
Signature
new StandardScaler(opts?: object): StandardScaler;
Parameters
Name | 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. Default Value true |
opts.with_mean? | boolean | If true , center the data before scaling. This does not work (and will 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. Default Value true |
opts.with_std? | boolean | If true , scale the data to unit variance (or equivalently, unit standard deviation). Default Value true |
Returns
Defined in: generated/preprocessing/StandardScaler.ts:23 (opens in a new tab)
Properties
_isDisposed
boolean
=false
Defined in: generated/preprocessing/StandardScaler.ts:21 (opens in a new tab)
_isInitialized
boolean
=false
Defined in: generated/preprocessing/StandardScaler.ts:20 (opens in a new tab)
_py
PythonBridge
Defined in: generated/preprocessing/StandardScaler.ts:19 (opens in a new tab)
id
string
Defined in: generated/preprocessing/StandardScaler.ts:16 (opens in a new tab)
opts
any
Defined in: generated/preprocessing/StandardScaler.ts:17 (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/preprocessing/StandardScaler.ts:515 (opens in a new tab)
mean_
The mean value for each feature in the training set. Equal to undefined
when with\_mean=False
.
Signature
mean_(): Promise<ArrayLike>;
Returns
Promise
<ArrayLike
>
Defined in: generated/preprocessing/StandardScaler.ts:444 (opens in a new tab)
n_features_in_
Number of features seen during fit.
Signature
n_features_in_(): Promise<number>;
Returns
Promise
<number
>
Defined in: generated/preprocessing/StandardScaler.ts:490 (opens in a new tab)
n_samples_seen_
The number of samples processed by the estimator for each feature. If there are no missing samples, the n\_samples\_seen
will be an integer, otherwise it will be an array of dtype int. If sample\_weights
are used it will be a float (if no missing data) or an array of dtype float that sums the weights seen so far. Will be reset on new calls to fit, but increments across partial\_fit
calls.
Signature
n_samples_seen_(): Promise<number | ArrayLike>;
Returns
Promise
<number
| ArrayLike
>
Defined in: generated/preprocessing/StandardScaler.ts:540 (opens in a new tab)
py
Signature
py(): PythonBridge;
Returns
PythonBridge
Defined in: generated/preprocessing/StandardScaler.ts:49 (opens in a new tab)
Signature
py(pythonBridge: PythonBridge): void;
Parameters
Name | Type |
---|---|
pythonBridge | PythonBridge |
Returns
void
Defined in: generated/preprocessing/StandardScaler.ts:53 (opens in a new tab)
scale_
Per feature relative scaling of the data to achieve zero mean and unit variance. Generally this is calculated using np.sqrt(var\_)
. If a variance is zero, we can’t achieve unit variance, and the data is left as-is, giving a scaling factor of 1. scale\_
is equal to undefined
when with\_std=False
.
Signature
scale_(): Promise<ArrayLike>;
Returns
Promise
<ArrayLike
>
Defined in: generated/preprocessing/StandardScaler.ts:421 (opens in a new tab)
var_
The variance for each feature in the training set. Used to compute scale\_
. Equal to undefined
when with\_std=False
.
Signature
var_(): Promise<ArrayLike>;
Returns
Promise
<ArrayLike
>
Defined in: generated/preprocessing/StandardScaler.ts:467 (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/preprocessing/StandardScaler.ts:104 (opens in a new tab)
fit()
Compute the mean and std to be used for later scaling.
Signature
fit(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike | The data used to compute the mean and standard deviation used for later scaling along the features axis. |
opts.sample_weight? | ArrayLike | Individual weights for each sample. |
opts.y? | any | Ignored. |
Returns
Promise
<any
>
Defined in: generated/preprocessing/StandardScaler.ts:121 (opens in a new tab)
fit_transform()
Fit to data, then transform it.
Fits transformer to X
and y
with optional parameters fit\_params
and returns a transformed version of X
.
Signature
fit_transform(opts: object): Promise<any[]>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike [] | Input samples. |
opts.fit_params? | any | Additional fit parameters. |
opts.y? | ArrayLike | Target values (undefined for unsupervised transformations). |
Returns
Promise
<any
[]>
Defined in: generated/preprocessing/StandardScaler.ts:170 (opens in a new tab)
get_feature_names_out()
Get output feature names for transformation.
Signature
get_feature_names_out(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.input_features? | any | Input features. |
Returns
Promise
<any
>
Defined in: generated/preprocessing/StandardScaler.ts:217 (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/preprocessing/StandardScaler.ts:62 (opens in a new tab)
inverse_transform()
Scale back the data to the original representation.
Signature
inverse_transform(opts: object): Promise<ArrayLike>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike | The data used to scale along the features axis. |
opts.copy? | boolean | Copy the input X or not. |
Returns
Promise
<ArrayLike
>
Defined in: generated/preprocessing/StandardScaler.ts:253 (opens in a new tab)
partial_fit()
Online computation of mean and std on X for later scaling.
All of X is processed as a single batch. This is intended for cases when fit
is not feasible due to very large number of n\_samples
or because X is read from a continuous stream.
The algorithm for incremental mean and std is given in Equation 1.5a,b in Chan, Tony F., Gene H. Golub, and Randall J. LeVeque. “Algorithms for computing the sample variance: Analysis and recommendations.” The American Statistician 37.3 (1983): 242-247:
Signature
partial_fit(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike | The data used to compute the mean and standard deviation used for later scaling along the features axis. |
opts.sample_weight? | ArrayLike | Individual weights for each sample. |
opts.y? | any | Ignored. |
Returns
Promise
<any
>
Defined in: generated/preprocessing/StandardScaler.ts:299 (opens in a new tab)
set_output()
Set output container.
See Introducing the set_output API for an example on how to use the API.
Signature
set_output(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.transform? | "default" | "pandas" | Configure output of transform and fit\_transform . |
Returns
Promise
<any
>
Defined in: generated/preprocessing/StandardScaler.ts:348 (opens in a new tab)
transform()
Perform standardization by centering and scaling.
Signature
transform(opts: object): Promise<ArrayLike>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | any [] | The data used to scale along the features axis. |
opts.copy? | boolean | Copy the input X or not. |
Returns
Promise
<ArrayLike
>
Defined in: generated/preprocessing/StandardScaler.ts:381 (opens in a new tab)