pyts.preprocessing.KBinsDiscretizer¶
-
class
pyts.preprocessing.KBinsDiscretizer(n_bins=5, strategy='quantile', raise_warning=True)[来源]¶ 将连续数据按样本分箱到区间中。
参数: - n_bins : int (default = 5)
要生成的箱数。箱的区间由输入数据的最小值和最大值决定。该值必须大于或等于2。
- strategy : ‘uniform’, ‘quantile’ or ‘normal’ (default = ‘quantile’)
用于定义箱宽的策略:
- ‘uniform’: 每个样本中的所有箱具有相同宽度
- ‘quantile’: 每个样本中的所有箱具有相同数量的点
- ‘normal’: 箱边界来自标准正态分布的分位数
- raise_warning : bool (default = True)
如果为True,当至少一个样本的箱数较小时会发出警告。在这种情况下,您应考虑减少箱数或移除这些样本。
示例
>>> 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]]
方法
__init__([n_bins, strategy, raise_warning])Initialize self. fit([X, y])Pass. fit_transform(X[, y])Fit to data, then transform it. 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=5, strategy='quantile', raise_warning=True)[来源]¶ 初始化自身。查看 help(type(self)) 获取准确的签名信息。
-
fit_transform(X, y=None, **fit_params)¶ 拟合数据,然后进行转换。
使用可选参数fit_params将转换器适配到X和y,并返回转换后的X版本。
参数: - X : array-like, shape = (n_samples, n_timestamps)
单变量时间序列。
- y : None or array-like, shape = (n_samples,) (default = None)
目标值(无监督转换时为None)。
- **fit_params : dict
额外的拟合参数。
返回值: - X_new : array
转换后的数组。
-
get_params(deep=True)¶ 获取此估计器的参数。
参数: - deep : bool, default=True
如果为True,将返回此估计器及其包含的子估计器的参数。
返回值: - params : dict
参数名称映射到对应的值。