pdmlabs.evaluation.vus.models.feature#

Classes of feature mapping for model type B

Classes

Stat([window, data_step, param, lag, freq])

statisitc feature extraction.

Window([window])

The class for rolling window feature mapping.

tf_Stat([window, step])

statisitc feature extraction using the tf_feature package.

class pdmlabs.evaluation.vus.models.feature.Stat(window=100, data_step=10, param=[{'coeff': 0, 'k': 5}], lag=1, freq=720)#

Bases: object

statisitc feature extraction. Features include [mean, variance, skewness, kurtosis, autocorrelation, maximum, minimum, entropy, seasonality, hurst component, AR coef]

ar_coefficient(x)#

This feature calculator fits the unconditional maximum likelihood of an autoregressive AR(k) process. The k parameter is the maximum lag of the process

\[X_{t}=\varphi_0 +\sum _{{i=1}}^{k}\varphi_{i}X_{{t-i}}+\varepsilon_{t}\]

For the configurations from param which should contain the maxlag “k” and such an AR process is calculated. Then the coefficients \(\varphi_{i}\) whose index \(i\) contained from “coeff” are returned.

Parameters:
  • x (numpy.ndarray) – the time series to calculate the feature of

  • param (list) – contains dictionaries {“coeff”: x, “k”: y} with x,y int

Return x:

the different feature values

Return type:

pandas.Series

autocorrelation(x)#

Calculates the autocorrelation of the specified lag, according to the formula [1]

\[\frac{1}{(n-l)\sigma^{2}} \sum_{t=1}^{n-l}(X_{t}-\mu )(X_{t+l}-\mu)\]

where \(n\) is the length of the time series \(X_i\), \(\sigma^2\) its variance and \(\mu\) its mean. l denotes the lag.

References

[1] https://en.wikipedia.org/wiki/Autocorrelation#Estimation

Parameters:
  • x (numpy.ndarray) – the time series to calculate the feature of

  • lag (int) – the lag

Returns:

the value of this feature

Return type:

float

convert(X)#
hurst_f(x)#
sample_entropy(x)#

Calculate and return sample entropy of x.

References

Parameters:

x (numpy.ndarray) – the time series to calculate the feature of

Returns:

the value of this feature

Return type:

float

class pdmlabs.evaluation.vus.models.feature.Window(window=100)#

Bases: object

The class for rolling window feature mapping. The mapping converts the original timeseries X into a matrix. The matrix consists of rows of sliding windows of original X.

convert(X)#
class pdmlabs.evaluation.vus.models.feature.tf_Stat(window=100, step=25)#

Bases: object

statisitc feature extraction using the tf_feature package. It calculates 763 features in total so it might be over complicated for some models. Recommend to use for methods like Isolation Forest which randomly picks a feature and then perform the classification. To use for other distance-based model like KNN, LOF, CBLOF, etc, first train to pass a function that give weights to individual features so that inconsequential features won’t cloud the important ones (mean, variance, kurtosis, etc).

convert(X)#