RobustScaler
- class dtaianomaly.preprocessing.RobustScaler(lower_quantile: float = 25.0, upper_quantile: float = 75.0)[source]
Scale the time series using robust statistics.
The
RobustScaleris similar toStandardScaler, but uses robust statistics rather than mean and standard deviation. The center of the data is computed via the median, and the scale is computed as the range between two quantiles (by default uses the IQR). This ensures that scaling is less affected by outliers.For a time series \(x\), center \(c\) and scale \(s\), observation \(x_i\) is scaled to observation \(y_i\) using the following equation:
\[y_i = \frac{x_i - c}{s}\]Notice the similarity with the formula for standard scaling. For multivariate time series, each attribute is scaled independently, each with an independent scale and center.
- Parameters:
- lower_quantilefloat, default=25.0
The lower quantile used to compute the scale. Must be in range [0.0, 100.0].
- upper_quantilefloat, default=75.0
The upper quantile used to compute the scale. Must be in range [0.0, 100.0].
- Attributes:
- center_array-like of shape (n_attributes)
The median value in each attribute of the training data.
- scale_array-like of shape (n_attributes)
The quantile range for each attribute of the training data.
- Raises:
- NotFittedError
If the transform method is called before fitting this StandardScaler.
Examples
>>> from dtaianomaly.preprocessing import RobustScaler >>> from dtaianomaly.data import demonstration_time_series >>> X, y = demonstration_time_series() >>> preprocessor = RobustScaler() >>> X_, y_ = preprocessor.fit_transform(X, y)
- check_is_fitted() None
Raise an error if this object is not fitted.
Check whether this object is fitted, and if it is not fitted, an exception is thrown.
- Raises:
- NotFittedError
If this object is not fitted.
- fit(X: ndarray, y: ndarray = None) Preprocessor
Fit this preprocessor.
First checks the inputs with
check_preprocessing_inputs(), and then fits this preprocessor.- Parameters:
- Xarray-like of shape (n_samples, n_attributes)
Raw time series.
- yarray-like, default=None
Ground-truth information.
- Returns:
- Preprocessor
Returns the fitted instance self.
- fit_transform(X: ~numpy.ndarray, y: ~numpy.ndarray = None) -> (<class 'numpy.ndarray'>, numpy.ndarray | None)
Fit this preprocessor and transform the given time series.
First checks the inputs with
check_preprocessing_inputs(), and then chains the fit and transform methods on the given data, i.e., first fit this preprocessor on the given X and y, after which the given X and y will be transformed.- Parameters:
- Xarray-like of shape (n_samples, n_attributes)
Raw time series.
- yarray-like of shape (n_samples), default=None
Ground-truth information.
- Returns:
- X_transformednp.ndarray of shape (n_samples, n_attributes)
Preprocessed raw time series.
- y_transformednp.ndarray of shape (n_samples)
The transformed ground truth. If no ground truth was provided (y=None), then None will be returned as well.
- is_fitted() bool
Check whether this object is fitted.
Check whether all the attributes of this object that end with an underscore (‘_’) has been initialized.
- Returns:
- bool
True if and only if all the attributes of this object ending with ‘_’ are initialized.
- requires_fitting() bool
Check whether this object requires fitting.
Check whether any of the attributes of this object ends with an underscore (‘_’), which indicates that the attribute is set when the object is fitted. Note that this method does not check whether the object is fitted, i.e., whether the attributes have been set.
- Returns:
- bool
True if and only if this object has attributes that end with ‘_’.
- transform(X: ~numpy.ndarray, y: ~numpy.ndarray = None) -> (<class 'numpy.ndarray'>, numpy.ndarray | None)
Transform the given time series.
First checks the inputs with
check_preprocessing_inputs(), and then transforms (i.e., preprocesses) the given time series.- Parameters:
- Xarray-like of shape (n_samples, n_attributes)
Raw time series.
- yarray-like of shape (n_samples), default=None
Ground-truth information.
- Returns:
- X_transformednp.ndarray of shape (n_samples, n_attributes)
Preprocessed raw time series.
- y_transformednp.ndarray of shape (n_samples)
The transformed ground truth. If no ground truth was provided (y=None), then None will be returned as well.