milia.features.window#
Per-window features for anomaly detection: shape, rolling statistics and spectrum.
Each row of the input is one window of readings, typically one meter-day. A detector run on raw readings alone misses the shape that separates a genuine anomaly from ordinary daily variation, so each window becomes its peak-normalised shape plus summary statistics and its strongest frequencies.
Functions
|
Column names matching |
|
Mean, standard deviation, mean absolute step change and range of one window. |
|
The largest non-constant FFT magnitudes of one window, largest first. |
|
Feature vector of one window: peak-normalised shape, |
Classes
|
Scikit-learn transformer applying |
- milia.features.window.rolling(profile)#
Mean, standard deviation, mean absolute step change and range of one window.
- Parameters:
profile (
ArrayLike) – Readings of one window, shape(steps,).- Return type:
- Returns:
The four statistics, in that order.
Examples
>>> rolling(np.array([1.0, 2.0, 1.0, 2.0])).round(2) array([1.5, 0.5, 1. , 1. ])
- milia.features.window.spectrum(profile, n=2)#
The largest non-constant FFT magnitudes of one window, largest first.
Captures periodic structure a reading-by-reading comparison misses, such as a cycling appliance.
- Parameters:
- Return type:
- Returns:
Array of shape
(n,).
Examples
>>> t = np.linspace(0, 2 * np.pi, 48, endpoint=False) >>> spectrum(np.sin(t) + 0.1 * np.sin(4 * t), n=2).round(1) array([24. , 2.4])
- milia.features.window.vector(profile, nfft=2)#
Feature vector of one window: peak-normalised shape,
rolling()andspectrum().- Parameters:
- Return type:
- Returns:
Array of shape
(steps + 4 + nfft,).
Examples
>>> vector(np.array([1.0, 2.0, 1.0, 2.0]), nfft=1).shape (9,)
- milia.features.window.names(steps, nfft=2)#
Column names matching
vector()’s layout.- Parameters:
- Return type:
- Returns:
shape0 ... shape<steps-1>,mean,std,change,range,fft1 ... fft<nfft>.
Examples
>>> names(2, nfft=1) ['shape0', 'shape1', 'mean', 'std', 'change', 'range', 'fft1']
- class milia.features.window.WindowFeatures(nfft=2)#
Bases:
TransformerMixin,BaseEstimatorScikit-learn transformer applying
vector()to every row.- Parameters:
nfft (
int) – Number of FFT magnitudes kept per window.
Examples
>>> WindowFeatures(nfft=3).fit_transform(np.random.default_rng(0).random((5, 24))).shape (5, 31)
- fit(X, y=None)#
Record the window length.
- Parameters:
- Return type:
- Returns:
The fitted transformer.