Skip to main content

Series Filtering

Remove series that don't meet quality criteria for forecasting.

FunctionDescription
drop_constantRemove series with no variation
drop_shortRemove series below minimum length
Showing 2 of 2

anofox_fcst_ts_drop_constant

Removes series exhibiting no variation (constant values). Constant series cannot be forecasted meaningfully.

Parameters

ParameterTypeRequiredDescription
table_nameVARCHARYesSource table
group_colANYYesGroup column
value_colDOUBLEYesValue column

Output

Returns filtered table excluding constant series.

Example

-- Remove products with no sales variation
SELECT * FROM anofox_fcst_ts_drop_constant(
'sales_by_product',
product_id,
sales
);
warning

May drop intermittent demand series with many zeros if gaps haven't been filled first. Fill gaps before filtering to preserve sparse series.


anofox_fcst_ts_drop_short

Filters out series shorter than a minimum length threshold. Short series don't have enough history for reliable forecasting.

Parameters

ParameterTypeRequiredDescription
table_nameVARCHARYesSource table
group_colANYYesGroup column
min_lengthINTEGERYesMinimum number of observations

Output

Returns filtered table excluding short series.

Example

-- Keep only products with at least 30 observations
SELECT * FROM anofox_fcst_ts_drop_short(
'sales_by_product',
product_id,
30
);

Minimum Length Guidelines

Model TypeRecommended Minimum
Naive / SMA10 observations
Exponential Smoothing20 observations
ARIMA30 observations
Seasonal models2+ full seasons
TBATS / MSTL3+ full seasons
warning

May drop intermittent demand series if gaps haven't been pre-filled. Fill gaps before filtering.


Filtering Workflow

-- 1. Fill gaps first (important!)
CREATE TABLE sales_filled AS
SELECT * FROM anofox_fcst_ts_fill_gaps(
'sales_by_product',
product_id,
date,
sales,
'1d'
);

-- 2. Remove constant series
CREATE TABLE sales_variable AS
SELECT * FROM anofox_fcst_ts_drop_constant(
'sales_filled',
product_id,
sales
);

-- 3. Remove short series
CREATE TABLE sales_ready AS
SELECT * FROM anofox_fcst_ts_drop_short(
'sales_variable',
product_id,
30
);

-- 4. Check how many series remain
SELECT COUNT(DISTINCT product_id) as remaining_products
FROM sales_ready;

Pre-Filtering Analysis

Before filtering, understand what you'll be removing:

-- Check series lengths
SELECT
product_id,
COUNT(*) as length,
CASE
WHEN COUNT(*) < 30 THEN 'Too short'
ELSE 'OK'
END as status
FROM sales_by_product
GROUP BY product_id
ORDER BY length;

-- Check for constant series
SELECT
product_id,
STDDEV(sales) as std_dev,
CASE
WHEN STDDEV(sales) = 0 THEN 'Constant'
ELSE 'Variable'
END as status
FROM sales_by_product
GROUP BY product_id;

🍪 Cookie Settings