Skip to content

Kurtosis Transform

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

\[ \kappa = \begin{cases} \frac{m_4}{m_2^2} - 3 & \text{Fisher} \\ \frac{m_4}{m_2^2} & \text{Pearson} \end{cases} \]

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

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

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

Bases: Transform

Compute the kurtosis of the values in x.

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

Compute the krutosis of the values in x where where is True.

The krutosis is a measure of the "tailedness" of a distribution. It is defined as the fourth standardized moment of a distribution, and is calculated as:

Parameters:

Name Type Description Default
signal_window ndarray

The signal to compute the krutosis of.

required
fisher Union[bool, bool_]

Whether to use Fisher's definition of kurtosis i.e. subtract 3 from the result. Default is True. If False, the result is the Pearson's definition of kurtosis.

True
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 krutosis of the values in x where where is True.

Examples

Fisher Kurtosis

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.KurtosisTransform()

# Get featurizer
featurizer = window.use(tf)

# Get features
features = featurizer(x)

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

Pearson Kurtosis

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.KurtosisTransform()

# Get featurizer
featurizer = window.use(tf)

# Get features
features = featurizer(x, fisher=False)

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

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