Skip to content

Data Sparsity Transform

The data sparsity transform computes the ratio of invalid values in a sliding window to the total number of values in the window. See NValidTransform for more details on how valid values are computed. Invalid values are computed by computing \(1 - N_{valid}\), where \(N_{valid}\) is the number of valid values in the signal window. It can be coupled with the SlidingWindow abstraction to compute the data_sparsity feature of a time series. It can be defined as:

\[ \text{sparsity} = \frac{N_{invalid}}{N_{total}} \]

where \(N_{invalid}\) is the number of invalid values in a window \(W\) and \(N_{total}\) is the total number of values in \(W\).

Bases: Transform

Compute the data sparsity of a signal window x.

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

Compute the data sparsity of the array x.

Parameters:

Name Type Description Default
signal_window ndarray

The signal window to find the data sparsity 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_]

A scalar value representing the data sparsity of x.

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

# 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 ⭐️.