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. Used when strategy="quantile". 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. |
Returns
Defined in: generated/preprocessing/KBinsDiscretizer.ts:23 (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:385 (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:466 (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:412 (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:439 (opens in a new tab)
py
Signature
py(): PythonBridge;Returns
PythonBridge
Defined in: generated/preprocessing/KBinsDiscretizer.ts:64 (opens in a new tab)
Signature
py(pythonBridge: PythonBridge): void;Parameters
| Name | Type |
|---|---|
pythonBridge | PythonBridge |
Returns
void
Defined in: generated/preprocessing/KBinsDiscretizer.ts:68 (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:125 (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.y? | any | Ignored. This parameter exists only for compatibility with Pipeline. |
Returns
Promise<any>
Defined in: generated/preprocessing/KBinsDiscretizer.ts:142 (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:184 (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:235 (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:77 (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:275 (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:315 (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:350 (opens in a new tab)