Scale¶
Defined in fynance.features.scale
- class Scale(X, kind='std', a=0., b=1., axis=0, **kwargs)[source]
Bases:
objectFit/transform-style scaler for time-series data.
Wraps the four scaling primitives (
standardize,normalize,roll_standardize,roll_normalize) behind a uniform fit / scale / revert API. Parameters are fitted once at construction and reused on subsequent calls — the typical pipeline pattern of fitting on a training window and applying the same transform to the test window, which avoids leaking test-period statistics into training.The
revertmethod inverts the transformation, useful when the target of an ML model was scaled and the prediction must be converted back to the original units.- Parameters:
- Xnp.ndarray[dtype, ndim=1 or 2]
Data to fit the parameters of scale transformation.
- kindstr, optional
“std” : Standardized scale transformation (default), see
standardize.“norm” : Normalized scale transformation, see
normalize.“raw” : No scale is apply.
“roll_std” : Standardized scale transformation, computed with rolling mean and standard deviation (see
roll_standardize).“roll_norm” : Normalized scale transformation, computed with roling minimum and maximum (see
roll_normalize).
- a, bfloat or array_like, optional
Some scale factors to apply after the transformation. By default is respectively 0 and 1.
- axisint, optional
Axis along which compute the scale parameters. Default is 0.
- **kwargskeyword arguments for particular functions
E.g: for rolling function set
wthe lagged window (seeroll_normalize) or for rolling standardization setkind_moment={"s", "w", "e"}(seeroll_standardize).
- Attributes:
- funccallable
The scale function.
- revert_funccallable
The revert scale function.
- paramsdict
Parameters of the scale transformation.
- axisint
The axis along which is computed the scale parameters.
- kindstr
The kind of scale transformation.
Methods
fit(X[, kind, a, b, axis])Compute the parameters of the scale transformation.
scale(X[, axis])Scale the data with the fitted parameters.
revert(X[, axis])Revert the transformation of the scale with the fitted parameters.
See also
normalize,standardize,roll_standardize,roll_normalize
- __call__(X, axis=None)[source]
Callable method to scale data with fitted parameters.
- Parameters:
- Xnp.ndarray[dtype, ndim=1 or 2]
Data to scale.
- Returns:
- np.ndarray[dtype, ndim=1 or 2]
Scalled data.
- fit(X, kind=None, a=0., b=1., axis=0, **kwargs)[source]
Compute the parameters of the scale transformation.
- Parameters:
- Xnp.ndarray[dtype, ndim=1 or 2]
Data to fit the parameters of scale transformation.
- kindstr, optional
“std” : Standardized scale transformation (default), see
standardize.“norm” : Normalized scale transformation, see
normalize.“raw” : No scale is apply.
“roll_std” : Standardized scale transformation, computed with rolling mean and standard deviation (see
roll_standardize).“roll_norm” : Normalized scale transformation, computed with roling minimum and maximum (see
roll_normalize).
- a, bfloat or array_like, optional
Some scale factors to apply after the transformation. By default is respectively 0 and 1.
- axisint, optional
Axis along which compute the scale parameters. Default is 0.
- **kwargskeyword arguments for particular functions
E.g: for rolling function set
wthe lagged window (seeroll_normalize) or for rolling standardization setkind_moment={"s", "w", "e"}(seeroll_standardize).
- revert(X, axis=None)[source]
Revert the transformation of the scale with the fitted parameters.
- Parameters:
- Xnp.ndarray[dtype, ndim=1 or 2]
Data to revert the scale.
- Returns:
- np.ndarray[dtype, ndim=1 or 2]
The revert transformed data.
- scale(X, axis=None)[source]
Scale the data with the fitted parameters.
- Parameters:
- Xnp.ndarray[dtype, ndim=1 or 2]
Data to scale.
- Returns:
- np.ndarray[dtype, ndim=1 or 2]
Scalled data.