KBinsDiscretizer#

class pyts.preprocessing.KBinsDiscretizer(n_bins: int = 5, strategy: str = 'quantile', raise_warning: bool = True)[source]#

Bin continuous data into intervals sample-wise.

Parameters:
n_binsint (default = 5)

The number of bins to produce. The intervals for the bins are determined by the minimum and maximum of the input data. It must be greater than or equal to 2.

strategy‘uniform’, ‘quantile’ or ‘normal’ (default = ‘quantile’)

Strategy used to define the widths of the bins:

  • ‘uniform’: All bins in each sample have identical widths

  • ‘quantile’: All bins in each sample have the same number of points

  • ‘normal’: Bin edges are quantiles from a standard normal distribution

raise_warningbool (default = True)

If True, a warning is raised when the number of bins is smaller for at least one sample. In this case, you should consider decreasing the number of bins or removing these samples.

Examples

>>> from pyts.preprocessing import KBinsDiscretizer
>>> X = [[0, 1, 0, 2, 3, 3, 2, 1],
...      [7, 0, 6, 1, 5, 3, 4, 2]]
>>> discretizer = KBinsDiscretizer(n_bins=2)
>>> print(discretizer.transform(X))
[[0 0 0 1 1 1 1 0]
 [1 0 1 0 1 0 1 0]]

Methods

__init__([n_bins, strategy, raise_warning])

fit([X, y])

Pass.

fit_transform(X[, y])

Fit to data, then transform it.

get_metadata_routing()

Get metadata routing of this object.

get_params([deep])

Get parameters for this estimator.

set_params(**params)

Set the parameters of this estimator.

transform(X)

Bin the data.

__init__(n_bins: int = 5, strategy: str = 'quantile', raise_warning: bool = True) → None[source]#
fit(X: ArrayLike | None = None, y: ArrayLike | None = None) → Self[source]#

Pass.

Parameters:
X

Ignored

y

Ignored

Returns:
selfobject
transform(X: ArrayLike) → NDArray[int64][source]#

Bin the data.

Parameters:
Xarray-like, shape = (n_samples, n_timestamps)

Data to transform.

Returns:
X_newarray-like, shape = (n_samples, n_timestamps)

Binned data.