Skip to main content

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

ParameterTypeRequiredDefaultDescription
yDOUBLEYes-Demand values over time
optionsMAPNo-Configuration options

Options MAP:

OptionTypeDefaultDescription
intermittent_thresholdDOUBLE0.3Zero proportion cutoff for intermittent classification
outlier_methodVARCHARzscoreOutlier detection: zscore (mean±3σ) or iqr (1.5×IQR)

Output Fields

FieldTypeDescription
demand_typeVARCHARregular or intermittent
is_intermittentBOOLEANTrue if zero_proportion >= threshold
distributionVARCHARBest-fit distribution name
meanDOUBLEMean of values
varianceDOUBLEVariance of values
zero_proportionDOUBLEProportion of zero values
n_observationsBIGINTNumber of observations
has_stockoutsBOOLEANTrue if stockouts detected
is_new_productBOOLEANTrue if new product pattern (leading zeros)
is_obsolete_productBOOLEANTrue if obsolete pattern (trailing zeros)
stockout_countBIGINTNumber of stockout observations
new_product_countBIGINTNumber of leading zero observations
obsolete_product_countBIGINTNumber of trailing zero observations
high_outlier_countBIGINTNumber of unusually high values
low_outlier_countBIGINTNumber 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

ParameterTypeRequiredDefaultDescription
yDOUBLEYes-Demand values
optionsMAPNo-Configuration options

Options MAP:

OptionTypeDefaultDescription
intermittent_thresholdDOUBLE0.3Zero proportion cutoff
outlier_methodVARCHARzscoreOutlier detection: zscore or iqr

Output Fields (per observation)

Returns LIST(STRUCT) with one entry per input observation:

FieldTypeDescription
stockoutBOOLEANUnexpected zero in positive demand
new_productBOOLEANLeading zeros pattern
obsolete_productBOOLEANTrailing zeros pattern
high_outlierBOOLEANUnusually high value
low_outlierBOOLEANUnusually low value

Example

SELECT anofox_stats_aid_anomaly_agg(
daily_demand,
MAP {'outlier_method': 'iqr'}
) as anomalies
FROM demand_series;

Anomaly Definitions

AnomalyDefinition
StockoutZero value occurring between non-zero values (not at start or end)
New ProductLeading sequence of zeros (before first non-zero)
Obsolete ProductTrailing sequence of zeros (after last non-zero)
High OutlierValue > mean + 3×std (zscore) or > Q3 + 1.5×IQR (iqr)
Low OutlierNon-zero value < mean - 3×std (zscore) or < Q1 - 1.5×IQR (iqr)
🍪 Cookie Settings