pyts.preprocessing.RobustScaler¶
-
class
pyts.preprocessing.RobustScaler(with_centering=True, with_scaling=True, quantile_range=(25.0, 75.0))[来源]¶ 使用对异常值稳健的统计量来缩放样本。
该缩放器通过移除中位数并根据分位数范围(默认为IQR:四分位距)对数据进行缩放。 IQR是指第1四分位数(25%分位数)与第3四分位数(75%分位数)之间的范围。
对每个样本独立进行中心化和缩放处理,通过计算时间戳上的相关统计量。使用中位数和四分位距来转换数据。
数据集的标准化是许多机器学习估计器的常见需求。通常通过去除均值并缩放到单位方差来实现。然而,异常值往往会以负面方式影响样本均值/方差。在这种情况下,中位数和四分位距通常能提供更好的结果。
参数: - with_centering : bool (默认值 = True)
如果为True,则在缩放前对数据进行中心化处理。
- with_scaling : bool (默认值 = True)
如果为True,则将数据缩放到四分位距范围。
- quantile_range : tuple (q_min, q_max), 0.0 < q_min < q_max < 100.0
默认值: (25.0, 75.0) = (第一四分位数, 第三四分位数) = IQR
示例
>>> from pyts.preprocessing import RobustScaler >>> X = [[1, -2, 4], ... [-2, 1, 1], ... [2, 3, -2]] >>> scaler = RobustScaler() >>> scaler.transform(X) array([[ 0. , -1. , 1. ], [-2. , 0. , 0. ], [ 0. , 0.4, -1.6]])
方法
__init__([with_centering, with_scaling, …])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_output(*[, transform])Set output container. set_params(**params)Set the parameters of this estimator. transform(X)Scale the data. -
__init__(with_centering=True, with_scaling=True, quantile_range=(25.0, 75.0))[来源]¶ 初始化自身。查看 help(type(self)) 获取准确的签名信息。
-
fit_transform(X, y=None, **fit_params)¶ 拟合数据,然后进行转换。
使用可选参数fit_params将转换器适配到X和y,并返回转换后的X版本。
参数: - X : array-like of shape (n_samples, n_features)
输入样本。
- y : array-like of shape (n_samples,) or (n_samples, n_outputs), default=None
目标值(无监督转换时为None)。
- **fit_params : dict
额外的拟合参数。
返回值: - X_new : 形状为(n_samples, n_features_new)的ndarray数组
转换后的数组。
-
get_params(deep=True)¶ 获取此估计器的参数。
参数: - deep : bool, default=True
如果为True,将返回此估计器及其包含的子估计器的参数。
返回值: - params : dict
参数名称映射到对应的值。
-
set_output(*, transform=None)¶ 设置输出容器。
参见Introducing the set_output API 了解如何使用该API的示例。
参数: - transform : {“default”, “pandas”}, default=None
配置transform和fit_transform的输出格式。
- “default”: 转换器的默认输出格式
- “pandas”: 输出为DataFrame
- None: 保持转换配置不变
返回值: - self : 估计器实例
估计器实例。