DocumentationClassesKBinsDiscretizer

Class: KBinsDiscretizer

Bin continuous data into intervals.

Read more in the User Guide.

Python Reference

Constructors

new KBinsDiscretizer()

new KBinsDiscretizer(opts?): KBinsDiscretizer

Parameters

ParameterTypeDescription
opts?object-
opts.dtype?anyThe 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.
opts.n_bins?number | ArrayLikeThe number of bins to produce. Raises ValueError if n_bins < 2.
opts.random_state?numberDetermines 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.
opts.subsample?numberMaximum number of samples, used to fit the model, for computational efficiency. 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 KBinsDiscretizer

Defined in generated/preprocessing/KBinsDiscretizer.ts:23

Properties

PropertyTypeDefault valueDefined in
_isDisposedbooleanfalsegenerated/preprocessing/KBinsDiscretizer.ts:21
_isInitializedbooleanfalsegenerated/preprocessing/KBinsDiscretizer.ts:20
_pyPythonBridgeundefinedgenerated/preprocessing/KBinsDiscretizer.ts:19
idstringundefinedgenerated/preprocessing/KBinsDiscretizer.ts:16
optsanyundefinedgenerated/preprocessing/KBinsDiscretizer.ts:17

Accessors

bin_edges_

Get Signature

get bin_edges_(): Promise<any[]>

The edges of each bin. Contain arrays of varying shapes (n_bins_, ) Ignored features will have empty arrays.

Returns Promise<any[]>

Defined in generated/preprocessing/KBinsDiscretizer.ts:456


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/KBinsDiscretizer.ts:537


n_bins_

Get Signature

get n_bins_(): Promise<ArrayLike>

Number of bins per feature. Bins whose width are too small (i.e., <= 1e-8) are removed with a warning.

Returns Promise<ArrayLike>

Defined in generated/preprocessing/KBinsDiscretizer.ts:483


n_features_in_

Get Signature

get n_features_in_(): Promise<number>

Number of features seen during fit.

Returns Promise<number>

Defined in generated/preprocessing/KBinsDiscretizer.ts:510


py

Get Signature

get py(): PythonBridge

Returns PythonBridge

Set Signature

set py(pythonBridge): void

Parameters

ParameterType
pythonBridgePythonBridge

Returns void

Defined in generated/preprocessing/KBinsDiscretizer.ts:66

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/KBinsDiscretizer.ts:120


fit()

fit(opts): Promise<any>

Fit the estimator.

Parameters

ParameterTypeDescription
optsobject-
opts.sample_weight?ArrayLikeContains weight values to be associated with each sample. Cannot be used when strategy is set to "uniform".
opts.X?ArrayLike[]Data to be discretized.
opts.y?anyIgnored. This parameter exists only for compatibility with Pipeline.

Returns Promise<any>

Defined in generated/preprocessing/KBinsDiscretizer.ts:137


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

ParameterTypeDescription
optsobject-
opts.fit_params?anyAdditional fit parameters.
opts.X?ArrayLike[]Input samples.
opts.y?ArrayLikeTarget values (undefined for unsupervised transformations).

Returns Promise<any[]>

Defined in generated/preprocessing/KBinsDiscretizer.ts:183


get_feature_names_out()

get_feature_names_out(opts): Promise<any>

Get output feature names.

Parameters

ParameterTypeDescription
optsobject-
opts.input_features?anyInput features.

Returns Promise<any>

Defined in generated/preprocessing/KBinsDiscretizer.ts:229


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

ParameterTypeDescription
optsobject-
opts.routing?anyA MetadataRequest encapsulating routing information.

Returns Promise<any>

Defined in generated/preprocessing/KBinsDiscretizer.ts:267


init()

init(py): Promise<void>

Initializes the underlying Python resources.

This instance is not usable until the Promise returned by init() resolves.

Parameters

ParameterType
pyPythonBridge

Returns Promise<void>

Defined in generated/preprocessing/KBinsDiscretizer.ts:79


inverse_transform()

inverse_transform(opts): Promise<ArrayLike>

Transform discretized data back to original feature space.

Note that this function does not regenerate the original data due to discretization rounding.

Parameters

ParameterTypeDescription
optsobject-
opts.X?ArrayLike[]Transformed data in the binned space.
opts.Xt?ArrayLike[]Transformed data in the binned space.

Returns Promise<ArrayLike>

Defined in generated/preprocessing/KBinsDiscretizer.ts:305


set_fit_request()

set_fit_request(opts): Promise<any>

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:

Parameters

ParameterTypeDescription
optsobject-
opts.sample_weight?string | booleanMetadata routing for sample_weight parameter in fit.

Returns Promise<any>

Defined in generated/preprocessing/KBinsDiscretizer.ts:350


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

ParameterTypeDescription
optsobject-
opts.transform?"default" | "pandas" | "polars"Configure output of transform and fit_transform.

Returns Promise<any>

Defined in generated/preprocessing/KBinsDiscretizer.ts:388


transform()

transform(opts): Promise<ArrayLike>

Discretize the data.

Parameters

ParameterTypeDescription
optsobject-
opts.X?ArrayLike[]Data to be discretized.

Returns Promise<ArrayLike>

Defined in generated/preprocessing/KBinsDiscretizer.ts:422