pyts.preprocessing
.KBinsDiscretizer¶
-
class
pyts.preprocessing.
KBinsDiscretizer
(n_bins=5, strategy='quantile')[source]¶ Bin continuous data into intervals sample-wise.
Parameters: - n_bins : int (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
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__
(self[, n_bins, strategy])Initialize self. fit
(self[, X, y])Pass. fit_transform
(self, X[, y])Fit to data, then transform it. get_params
(self[, deep])Get parameters for this estimator. set_params
(self, \*\*params)Set the parameters of this estimator. transform
(self, X)Bin the data. -
__init__
(self, n_bins=5, strategy='quantile')[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
fit_transform
(self, X, y=None, **fit_params)¶ 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: - X : numpy array of shape [n_samples, n_features]
Training set.
- y : numpy array of shape [n_samples]
Target values.
- **fit_params : dict
Additional fit parameters.
Returns: - X_new : numpy array of shape [n_samples, n_features_new]
Transformed array.
-
get_params
(self, deep=True)¶ Get parameters for this estimator.
Parameters: - deep : bool, default=True
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Returns: - params : mapping of string to any
Parameter names mapped to their values.
-
set_params
(self, **params)¶ Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as pipelines). The latter have parameters of the form
<component>__<parameter>
so that it’s possible to update each component of a nested object.Parameters: - **params : dict
Estimator parameters.
Returns: - self : object
Estimator instance.