KBinsDiscretizer
Bin continuous data into intervals.
Read more in the User Guide.
Python Reference (opens in a new tab)
Constructors
constructor()
Signature
new KBinsDiscretizer(opts?: object): KBinsDiscretizer;
Parameters
Name | Type | Description |
---|---|---|
opts? | object | - |
opts.dtype? | any | The desired data-type for the output. If undefined , output dtype is consistent with input dtype. Only np.float32 and np.float64 are supported. |
opts.encode? | "onehot" | "onehot-dense" | "ordinal" | Method used to encode the transformed result. Default Value 'onehot' |
opts.n_bins? | number | ArrayLike | The number of bins to produce. Raises ValueError if n\_bins < 2 . Default Value 5 |
opts.random_state? | number | Determines random number generation for subsampling. Pass an int for reproducible results across multiple function calls. See the subsample parameter for more details. See Glossary. |
opts.strategy? | "uniform" | "quantile" | "kmeans" | Strategy used to define the widths of the bins. Default Value 'quantile' |
opts.subsample? | number | Maximum number of samples, used to fit the model, for computational efficiency. Defaults to 200_000 when strategy='quantile' and to undefined when strategy='uniform' or strategy='kmeans' . subsample=None means that all the training samples are used when computing the quantiles that determine the binning thresholds. Since quantile computation relies on sorting each column of X and that sorting has an n log(n) time complexity, it is recommended to use subsampling on datasets with a very large number of samples. Default Value 'warn' |
Returns
Defined in: generated/preprocessing/KBinsDiscretizer.ts:23 (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/KBinsDiscretizer.ts:127 (opens in a new tab)
fit()
Fit the estimator.
Signature
fit(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike [] | Data to be discretized. |
opts.sample_weight? | ArrayLike | Contains weight values to be associated with each sample. Only possible when strategy is set to "quantile" . |
opts.y? | any | Ignored. This parameter exists only for compatibility with Pipeline . |
Returns
Promise
<any
>
Defined in: generated/preprocessing/KBinsDiscretizer.ts:144 (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/KBinsDiscretizer.ts:195 (opens in a new tab)
get_feature_names_out()
Get output feature names.
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/KBinsDiscretizer.ts:246 (opens in a new tab)
get_metadata_routing()
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
Signature
get_metadata_routing(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.routing? | any | A MetadataRequest encapsulating routing information. |
Returns
Promise
<any
>
Defined in: generated/preprocessing/KBinsDiscretizer.ts:286 (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/KBinsDiscretizer.ts:79 (opens in a new tab)
inverse_transform()
Transform discretized data back to original feature space.
Note that this function does not regenerate the original data due to discretization rounding.
Signature
inverse_transform(opts: object): Promise<ArrayLike>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.Xt? | ArrayLike [] | Transformed data in the binned space. |
Returns
Promise
<ArrayLike
>
Defined in: generated/preprocessing/KBinsDiscretizer.ts:325 (opens in a new tab)
set_fit_request()
Request metadata passed to the fit
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:
Signature
set_fit_request(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.sample_weight? | string | boolean | Metadata routing for sample\_weight parameter in fit . |
Returns
Promise
<any
>
Defined in: generated/preprocessing/KBinsDiscretizer.ts:367 (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/KBinsDiscretizer.ts:407 (opens in a new tab)
transform()
Discretize the data.
Signature
transform(opts: object): Promise<ArrayLike>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike [] | Data to be discretized. |
Returns
Promise
<ArrayLike
>
Defined in: generated/preprocessing/KBinsDiscretizer.ts:442 (opens in a new tab)
Properties
_isDisposed
boolean
=false
Defined in: generated/preprocessing/KBinsDiscretizer.ts:21 (opens in a new tab)
_isInitialized
boolean
=false
Defined in: generated/preprocessing/KBinsDiscretizer.ts:20 (opens in a new tab)
_py
PythonBridge
Defined in: generated/preprocessing/KBinsDiscretizer.ts:19 (opens in a new tab)
id
string
Defined in: generated/preprocessing/KBinsDiscretizer.ts:16 (opens in a new tab)
opts
any
Defined in: generated/preprocessing/KBinsDiscretizer.ts:17 (opens in a new tab)
Accessors
bin_edges_
The edges of each bin. Contain arrays of varying shapes (n\_bins\_, )
Ignored features will have empty arrays.
Signature
bin_edges_(): Promise<any[]>;
Returns
Promise
<any
[]>
Defined in: generated/preprocessing/KBinsDiscretizer.ts:477 (opens in a new tab)
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/KBinsDiscretizer.ts:558 (opens in a new tab)
n_bins_
Number of bins per feature. Bins whose width are too small (i.e., <= 1e-8) are removed with a warning.
Signature
n_bins_(): Promise<ArrayLike>;
Returns
Promise
<ArrayLike
>
Defined in: generated/preprocessing/KBinsDiscretizer.ts:504 (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/KBinsDiscretizer.ts:531 (opens in a new tab)
py
Signature
py(): PythonBridge;
Returns
PythonBridge
Defined in: generated/preprocessing/KBinsDiscretizer.ts:66 (opens in a new tab)
Signature
py(pythonBridge: PythonBridge): void;
Parameters
Name | Type |
---|---|
pythonBridge | PythonBridge |
Returns
void
Defined in: generated/preprocessing/KBinsDiscretizer.ts:70 (opens in a new tab)