Skip to content

Quantile Function

The quantile function computes the q-th quantile of the data in the sliding window. The quantile is computed using the numpy.quantile function. The function can be combined with the SlidingWindow to compute the quantile of the data in a sliding window. We can use this function to compute the median of the data in a sliding window by setting q=0.5.

Compute the q-th quantile of the values in x.

Parameters:

Name Type Description Default
x ndarray

The array to compute the q-th quantile of.

required
q Union[float, float_]

The quantile to compute. q belongs to [0, 1].

required
method str

The method to use when computing the quantile. Default is 'linear'. See numpy.quantile for more information.

'linear'
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, float_]

The q-th quantile of the values in x.

Raises:

Type Description
ValueError

If q is not in [0, 1].

Examples

25th percentile

import numpy as np
import autonfeat as aft
import autonfeat.functional as F

# 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)

# Get featurizer
featurizer = window.use(F.quantile_tf)

# Get features
features = featurizer(x, q=0.25)

# Print features
print(features)

Median

import numpy as np
import autonfeat as aft
import autonfeat.functional as F

# 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)

# Get featurizer
featurizer = window.use(F.quantile_tf)

# Get features
features = featurizer(x, q=0.5)

# Print features
print(features)

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