Production Deployment
Scale and monitor regression models in production.
Model Storage
CREATE TABLE production_model AS
SELECT
'revenue_model_v1' as model_name,
coefficient,
std_error,
CURRENT_TIMESTAMP as created_at
FROM anofox_statistics_ols(
'all_historical_data',
'revenue',
ARRAY['marketing_spend', 'team_size']
);
Batch Prediction
CREATE TABLE forecast_results AS
SELECT
date,
marketing_spend,
predicted_revenue,
lower_95,
upper_95
FROM upcoming_periods
CROSS JOIN LATERAL anofox_statistics_model_predict(
'production_model',
upcoming_periods,
0.95
);
Performance Monitoring
CREATE VIEW model_health AS
SELECT
DATE_TRUNC('week', date) as week,
COUNT(*) as n_obs,
SQRT(AVG((actual - predicted)^2)) as rmse,
CASE WHEN rmse > 300000 THEN 'ALERT' ELSE 'OK' END as status
FROM predictions
GROUP BY week
ORDER BY week DESC;
Retraining
-- Monthly refit
CREATE TABLE model_v2 AS
SELECT * FROM anofox_statistics_ols(
'recent_data_last_90_days',
'revenue',
ARRAY['marketing_spend', 'team_size']
);
-- Compare AIC
SELECT aic FROM model_v1 vs model_v2;
-- Deploy v2 if better
Next Steps
- Basic Workflow — End-to-end review
- Reference — Complete API