Skip to content

Skewness Transform

The skew transform computes the skewness of a window. When combined with the SlidingWindow abstraction, the skew transform can be used to compute the skew feature of a time series. The skewness is defined as:

\[ \gamma = \frac{m_3}{m_2^{3/2}} \]

We use this and correct for statistical bias. The Fisher-Pearson standardized moment coefficient is defined as:

\[ \Gamma = \gamma \sqrt{\frac{N(N-1)}{N-2}} \]

where \(m_2\) and \(m_3\) are the second and third central moments, respectively. They are defined as:

\[ m_2 = \frac{1}{N} \sum_{i=1}^N (x_i - \bar{x})^2 \]
\[ m_3 = \frac{1}{N} \sum_{i=1}^N (x_i - \bar{x})^3 \]

where \(N\) is the number of samples in the window and \(\bar{x}\) is the mean of the window.

Bases: Transform

Compute the skewness of the values in x.

__call__(signal_window, where=lambda : not np.isnan(x))

Compute the skewness of the values in x where where is True. The skewness is computed using the Fisher-Pearson standardized coefficient of skewness.

The skewness is only computed for valid values i.e. values where where is True. The skewness computed is corrected for statistical bias.

Parameters:

Name Type Description Default
signal_window ndarray

The signal to compute the skewness of.

required
where Callable[[Union[int, float, int_, float_]], Union[bool, bool_]]

A function that takes a value and returns True or False. Default is lambda x: not np.isnan(x) i.e. a measurement is valid if it is not a NaN value.

lambda : not numpy.isnan(x)

Returns:

Type Description
Union[float_, int_]

The skewness of the values in x where where is True.

Examples

import numpy as np
import autonfeat as aft

# Random data
n_samples = 100
x = np.random.rand(n_samples)

# Create sliding window
ws = 10
ss = 10
window = aft.SlidingWindow(window_size=ws, step_size=ss)

# Create transform
tf = aft.SkewnessTransform()

# Get featurizer
featurizer = window.use(tf)

# Get features
features = featurizer(x)

# Print features
print(window)
print(tf)
print(features)

If you enjoy using AutonFeat, please consider starring the repository ⭐️.