Demand Classification
Classify demand patterns and detect anomalies for inventory management.
AID - Demand Classification
Classifies demand patterns as regular or intermittent, identifies best-fit distribution, and detects various anomaly patterns.
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
y | DOUBLE | Yes | - | Demand values over time |
options | MAP | No | - | Configuration options |
Options MAP:
| Option | Type | Default | Description |
|---|---|---|---|
intermittent_threshold | DOUBLE | 0.3 | Zero proportion cutoff for intermittent classification |
outlier_method | VARCHAR | zscore | Outlier detection: zscore (mean±3σ) or iqr (1.5×IQR) |
Output Fields
| Field | Type | Description |
|---|---|---|
demand_type | VARCHAR | regular or intermittent |
is_intermittent | BOOLEAN | True if zero_proportion >= threshold |
distribution | VARCHAR | Best-fit distribution name |
mean | DOUBLE | Mean of values |
variance | DOUBLE | Variance of values |
zero_proportion | DOUBLE | Proportion of zero values |
n_observations | BIGINT | Number of observations |
has_stockouts | BOOLEAN | True if stockouts detected |
is_new_product | BOOLEAN | True if new product pattern (leading zeros) |
is_obsolete_product | BOOLEAN | True if obsolete pattern (trailing zeros) |
stockout_count | BIGINT | Number of stockout observations |
new_product_count | BIGINT | Number of leading zero observations |
obsolete_product_count | BIGINT | Number of trailing zero observations |
high_outlier_count | BIGINT | Number of unusually high values |
low_outlier_count | BIGINT | Number of unusually low values |
Example
SELECT
sku_id,
(result).demand_type,
(result).is_intermittent,
(result).distribution,
(result).zero_proportion,
(result).has_stockouts,
(result).high_outlier_count
FROM (
SELECT
sku_id,
anofox_stats_aid_agg(
daily_demand,
MAP {'intermittent_threshold': '0.3', 'outlier_method': 'zscore'}
) as result
FROM inventory_data
GROUP BY sku_id
);
AID Anomaly Detection
Returns per-observation anomaly flags for demand analysis while maintaining input order.
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
y | DOUBLE | Yes | - | Demand values |
options | MAP | No | - | Configuration options |
Options MAP:
| Option | Type | Default | Description |
|---|---|---|---|
intermittent_threshold | DOUBLE | 0.3 | Zero proportion cutoff |
outlier_method | VARCHAR | zscore | Outlier detection: zscore or iqr |
Output Fields (per observation)
Returns LIST(STRUCT) with one entry per input observation:
| Field | Type | Description |
|---|---|---|
stockout | BOOLEAN | Unexpected zero in positive demand |
new_product | BOOLEAN | Leading zeros pattern |
obsolete_product | BOOLEAN | Trailing zeros pattern |
high_outlier | BOOLEAN | Unusually high value |
low_outlier | BOOLEAN | Unusually low value |
Example
SELECT anofox_stats_aid_anomaly_agg(
daily_demand,
MAP {'outlier_method': 'iqr'}
) as anomalies
FROM demand_series;
Anomaly Definitions
| Anomaly | Definition |
|---|---|
| Stockout | Zero value occurring between non-zero values (not at start or end) |
| New Product | Leading sequence of zeros (before first non-zero) |
| Obsolete Product | Trailing sequence of zeros (after last non-zero) |
| High Outlier | Value > mean + 3×std (zscore) or > Q3 + 1.5×IQR (iqr) |
| Low Outlier | Non-zero value < mean - 3×std (zscore) or < Q1 - 1.5×IQR (iqr) |