What you will be able to do
- Fit a straight-line trend with REGR_SLOPE and REGR_INTERCEPT, apply it to a new x value, and judge the fit with REGR_R2
- Train a SNOWFLAKE.ML.FORECAST model object and call its FORECAST method with the correct syntax
- Forecast many series from one model with SERIES_COLNAME, and forecast with exogenous features by supplying future feature rows
- Read FORECAST, LOWER_BOUND and UPPER_BOUND, and assess a model with SHOW_EVALUATION_METRICS and EXPLAIN_FEATURE_IMPORTANCE
Key concept
Train-then-call model object — Snowflake's ML functions are not functions you apply to a column. You first create a schema-level model object from training data with CREATE SNOWFLAKE.ML followed by the class name, such as FORECAST, then call methods on that object with the model!METHOD(...) syntax to get predictions, metrics and explanations.
1.A linear trend in plain SQL with REGR_SLOPE, REGR_INTERCEPT and REGR_R2
The cheapest prediction in Snowflake is a straight line. Three aggregate functions from the linear regression family fit one in a single query, with no model object and no training step. REGR_SLOPE(y, x) gives the line's slope and REGR_INTERCEPT(y, x) gives where it crosses x = 0, so the line is y = intercept + slope × x. REGR_R2(y, x) tells you how much to trust that line.
Argument order is the first thing to get right. All three take the dependent variable (the thing you want to predict) first and the independent variable second. Write REGR_SLOPE(revenue, day_number), not the reverse. If you swap them, you get the slope of a different regression, and nothing raises an error. Both arguments must evaluate to numbers, so a trend over time needs the date turned into a numeric x first, such as a day count.
| Function | Computed as | Use it to |
|---|---|---|
| REGR_SLOPE(y, x) | COVAR_POP(x,y) / VAR_POP(x) | Get the change in y per unit of x (the trend rate) |
| REGR_INTERCEPT(y, x) | AVG(y) - REGR_SLOPE(y,x) * AVG(x) | Anchor the line, so you can compute intercept + slope × x for a new x |
| REGR_R2(y, x) | POWER(CORR(y,x), 2); NULL if VAR_POP(x) = 0 | Judge the fit: near 1 means the line explains y well |
Only non-null pairs count. A row where either y or x is NULL is dropped from the fit. In the example below, group 1 has one row and its x is NULL, so it has no usable pairs and returns NULL. Group 2's row (25, null) is ignored, and its other three rows give a slope of 0.831408776. On the same data, REGR_INTERCEPT(v, v2) returns 1.154734411 for group 2 and REGR_R2(v, v2) returns 0.9976905312, which means the fit is almost perfect.
CREATE OR REPLACE TABLE aggr(k INT, v DECIMAL(10,2), v2 DECIMAL(10, 2));
INSERT INTO aggr VALUES(1, 10, null);
INSERT INTO aggr VALUES(2, 10, 11), (2, 20, 22), (2, 25, null), (2, 30, 35);
SELECT k, REGR_SLOPE(v, v2) FROM aggr GROUP BY k;About 34.41: 1.154734411 + 0.831408776 × 40 = 1.1547 + 33.2564. With an R² of 0.998 the line fits the observed points closely, but it still assumes the trend keeps going straight.
These functions also run as window functions with PARTITION BY, which gives you one slope per product on every row. However, they reject an ORDER BY or an explicit frame inside OVER, so a rolling-window regression cannot be written this way.
Checkpoint 1 of 8· Check yourself
A daily sales table has 30 rows per product. For one product, 4 rows have a NULL revenue because those days are not reported yet, but every row has a day_number. What does SELECT product, REGR_SLOPE(revenue, day_number) ... GROUP BY product return for that product?
The REGR_ functions use only complete (y, x) pairs, so a row where either value is NULL is dropped and the line is fitted on the rest. The result is NULL only when a group has no complete pair at all, like group 1 in the example.
“In these instances, the aggregate function ignores a row if any individual column is NULL.”Source: docs.snowflake.com
2.Training a FORECAST model and calling it
A straight line misses weekly cycles, holiday spikes and uncertainty. SNOWFLAKE.ML.FORECAST is a built-in machine learning function that predicts future values of a numeric time series and returns a range around each prediction. The input needs at least a timestamp column and a numeric target, ideally at a fixed interval. Training still works on real data with missing, duplicate or misaligned time steps. Your role must own the schema or hold the CREATE SNOWFLAKE.ML.FORECAST privilege on it, because the model is stored there.
Forecasting takes two statements. The first, CREATE SNOWFLAKE.ML.FORECAST, trains a named model from a reference to your data. The second calls that model's FORECAST method. The call uses an exclamation mark between the model name and the method, and named arguments with =>, for example CALL model1!FORECAST(FORECASTING_PERIODS => 3). A dot (model.FORECAST) is not method syntax. Neither is a positional argument (FORECAST(30)). The forecast horizon is never part of CREATE: the CREATE statement takes only the data and column names, and you choose how many periods to predict each time you call.
CREATE SNOWFLAKE.ML.FORECAST model1(
INPUT_DATA => TABLE(v1),
TIMESTAMP_COLNAME => 'date',
TARGET_COLNAME => 'sales'
);You don't declare the spacing between timestamps. The model infers it from the training data, so daily history gives daily forecasts. Each output row has five columns:
| Column | Meaning |
|---|---|
| SERIES | Which series the row belongs to; NULL for a single-series model |
| TS | The future timestamp being predicted |
| FORECAST | The predicted value |
| LOWER_BOUND | Bottom of the prediction interval |
| UPPER_BOUND | Top of the prediction interval |
Read the bounds alongside the forecast. LOWER_BOUND and UPPER_BOUND form the range the actual value is expected to fall in. When the history is perfectly regular, as in the documentation's toy series of 2, 3, 4…, the model makes zero errors, so both bounds equal FORECAST. Real data gives a range, and a wide range is a warning that the point forecast is soft. To change how much of the actual data the range should cover, pass prediction_interval in a configuration object, for example CALL model1!FORECAST(FORECASTING_PERIODS => 3, CONFIG_OBJECT => {'prediction_interval': 0.8});.
To query the output or store it, call the method inside TABLE(...) in a FROM clause and drop the CALL keyword. This also lets a dashboard query pick out the FORECAST and bound columns by name.
CREATE TABLE my_forecasts AS
SELECT * FROM TABLE(model1!FORECAST(FORECASTING_PERIODS => 3));Checkpoint 2 of 8· Fill the gap
A dashboard needs the forecast stored as a table. Which keyword completes this statement?
CREATE TABLE my_forecasts AS
SELECT * FROM ? (model1!FORECAST(FORECASTING_PERIODS => 3));To use forecast output in a FROM clause, you leave out the CALL keyword and wrap the method call in TABLE(...). CALL works only as a standalone statement and cannot go inside a SELECT. The horizon is still set at call time with FORECASTING_PERIODS => 3.
Source: docs.snowflake.comCheckpoint 3 of 8· Exam question
An analyst owns the table DAILY_SALES(sale_date DATE, revenue NUMBER) with three years of one continuous daily series. The business wants a 30-day revenue forecast from Snowflake's built-in ML function. Which approach produces it?
Correct answer: D — Run CREATE SNOWFLAKE.ML.FORECAST sales_model(INPUT_DATA => TABLE(daily_sales), TIMESTAMP_COLNAME => 'sale_date', TARGET_COLNAME => 'revenue'), then CALL sales_model!FORECAST(FORECASTING_PERIODS => 30).
- A. Incorrect. No such one-shot procedure exists; training and prediction are separate steps, and the trained model persists as an object in the schema.
- B. Incorrect. Methods on a model object use the bang syntax with a CALL statement and named arguments such as FORECASTING_PERIODS, not a dotted TABLE() reference.
- C. Incorrect. Forecasting is not a window function; it is a model class that must be created as a schema object and then invoked through its methods.
- D. Correct. Forecasting is a two-step flow: train a model object from the table with timestamp and target columns, then call its FORECAST method with the number of periods to predict.
Sources4
3.One model for many series with SERIES_COLNAME
Without a series column, every row in the input belongs to one series. Sales from 200 stores would be treated as a single timeline with many values per date. Adding SERIES_COLNAME makes one CREATE statement train an independent forecast for each distinct value of that column. Each output row carries its series identifier in the SERIES column.
When a series is defined by more than one column, combine them into a single column first. The documentation builds the view CREATE OR REPLACE VIEW v3 AS SELECT [store_id, item] AS store_item, date, sales FROM sales_data;, which puts store and item into an array, and then names store_item as the series column. Don't change the timestamp column or pre-aggregate with GROUP BY to get the same result. The timestamp has to stay a timestamp, and grouping merges the stores into one series instead of separating them.
CREATE SNOWFLAKE.ML.FORECAST model2(
INPUT_DATA => TABLE(v3),
SERIES_COLNAME => 'store_item',
TIMESTAMP_COLNAME => 'date',
TARGET_COLNAME => 'sales'
);CALL model2!FORECAST(FORECASTING_PERIODS => 2); returns two rows for every series. If you only need one series, ask for it directly with CALL model2!FORECAST(SERIES_VALUE => [2,'umbrella'], FORECASTING_PERIODS => 2);. That generates only the umbrella forecast, which is cheaper than generating all of them and filtering afterwards.
Checkpoint 4 of 8· Check yourself
You need a separate sales forecast for every store and item pair in sales_data, which has store_id, item, date and sales columns. You want to train it all in one CREATE statement. Which setup does that?
SERIES_COLNAME takes a single column, so when a series is defined by more than one column you combine those columns first. One CREATE then trains an independent forecast for each distinct value. Grouping the rows merges the stores into one timeline instead of separating them. The timestamp column must stay a timestamp. SERIES_VALUE only selects a series that the model already learned from SERIES_COLNAME.
“create a new column that combines these values, and specify that as the series column.”Source: docs.snowflake.com
Checkpoint 5 of 8· Exam question
A retailer keeps STORE_SALES(store_id, sale_date, units) for 200 stores. The analyst wants one forecasting model that trains a separate forecast for every store and returns results labelled by store. What should the CREATE statement include?
Correct answer: A — Include SERIES_COLNAME => 'store_id' so one model trains an independent forecast per store, and results carry the store in the SERIES column.
- A. Correct. SERIES_COLNAME marks the column that identifies individual series, so a single model object trains all 200 series and labels each prediction row.
- B. Incorrect. The timestamp column must be a real date or timestamp type; a concatenated string breaks time ordering and does not identify series.
- C. Incorrect. Looping is unnecessary because multi-series support is built in, and it would produce 200 model objects to maintain and retrain.
- D. Incorrect. Aggregating by store collapses the data rather than declaring series, so the model would not produce per-store forecasts.
Sources4
4.Forecasting with exogenous features
Features are other factors you believe move the target, such as temperature, a promotion flag or a holiday name. You don't name them anywhere. CREATE only requires the timestamp and target columns, and any other column in the training input is treated as a feature. Training on a view of date, sales, temperature, humidity and holiday therefore produces a model that uses all three extra columns.
A feature-trained model only forecasts dates for which you supply future feature values. You pass a table or view of future rows that has the timestamp column and the same feature columns as training. You also pass TIMESTAMP_COLNAME so the method knows which column holds the dates. FORECASTING_PERIODS is left out, because the timestamps in that future table set the horizon: two rows give two forecasts, and fourteen rows give fourteen.
CALL model3!FORECAST(
INPUT_DATA => TABLE(v2_forecast),
TIMESTAMP_COLNAME =>'date'
);Checkpoint 6 of 8· Fill the gap
model3 was trained on date, sales, temperature, humidity and holiday. The view v2_forecast holds future dates and feature values but no sales column. Which named argument completes the forecast call?
CALL model3!FORECAST(
INPUT_DATA => TABLE(v2_forecast),
? =>'date'
);When a model was trained with features, you pass it the future feature rows through INPUT_DATA, and TIMESTAMP_COLNAME tells the method which column holds the dates. The target is what the model predicts, so the future rows have no target column to name. FORECASTING_PERIODS is left out because the timestamps in v2_forecast set the horizon.
Source: docs.snowflake.comCheckpoint 7 of 8· Exam question
A model was trained on SALES_HISTORY with extra columns promo_flag and holiday_name alongside the date and the target. The analyst now needs a 14-day forecast. Select TWO requirements for calling FORECAST correctly.(Select 2)
Correct answers: C, D — Supply future rows through INPUT_DATA that contain the timestamp column and the same extra feature columns for each of the 14 forecast dates.; Pass TIMESTAMP_COLNAME together with INPUT_DATA so the function knows which column in the future table holds the dates to predict.
- A. Incorrect. The horizon is a parameter of the FORECAST method call, not of model creation.
- B. Incorrect. The model does not predict its own exogenous inputs; without future values the call cannot use those features.
- C. Correct. Exogenous features need known values at every forecast timestamp, so a future-dated input must carry those columns.
- D. Correct. When future data is passed instead of FORECASTING_PERIODS, the call must name the timestamp column of that table.
- E. Incorrect. Extra columns are treated as features at training time automatically; no feature key exists in the call config.
Sources4
5.Judging a forecast model: evaluation metrics, feature importance and logs
Every forecast model scores itself during training. By default, Snowflake also trains models on subsets of your history, predicts the rows it held back, and compares those predictions with what actually happened. model!SHOW_EVALUATION_METRICS() returns the results of that cross-validation.
| Metric | Kind | What it measures |
|---|---|---|
| MAE | Point | Mean Absolute Error |
| MAPE / SMAPE | Point | Mean Absolute Percentage Error / its symmetric form |
| MSE | Point | Mean Squared Error |
| MDA | Point | Mean Directional Accuracy |
| COVERAGE_INTERVAL | Interval | Proportion of actual values that fall inside the prediction interval |
| WINKLER_ALPHA | Interval | Winkler Score for the interval |
Cross-validation is controlled through CONFIG_OBJECT keys: evaluate (set it to FALSE to skip evaluation), n_splits (default 1), max_train_size, test_size and gap. Small histories can end up with no metrics at all. Evaluation needs at least (n_splits × test_size) + gap training rows, and with the default single split the STANDARD_DEVIATION column is NULL. You can also call SHOW_EVALUATION_METRICS with new data that has actual values (INPUT_DATA, TIMESTAMP_COLNAME, TARGET_COLNAME) to score the model on data it never saw.
model!EXPLAIN_FEATURE_IMPORTANCE() ranks the features the model relied on. Each score is between 0 and 1, and the scores add up to 1. The ranking covers your own columns (FEATURE_TYPE user_provided), calendar features derived from the timestamp, and features derived from the target itself. Two near-identical features split the importance between them, so each looks less important than it is. If a model fails to fit for some series, model!SHOW_TRAINING_LOGS() reports the error for each of those series.
Checkpoint 8 of 8· Match them up
Match each method on a trained forecast model to the question it answers about that model.
Tap a term, then the definition that fits it.
Each of the three methods covers one job: SHOW_EVALUATION_METRICS judges accuracy, EXPLAIN_FEATURE_IMPORTANCE ranks the features, and SHOW_TRAINING_LOGS debugs training failures. On a forecast model, the feature-importance method is EXPLAIN_FEATURE_IMPORTANCE. SHOW_FEATURE_IMPORTANCE is the classification method and does not work on a forecast model.
“Assess your model’s accuracy. Understand the relative importance of the features the model was trained on. Debug training errors.”Source: docs.snowflake.com
Sources
(7)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.
“Returns the slope of the linear regression line for non-null pairs in a group.”
↩︎ A linear trend in plain SQL with REGR_SLOPE, REGR_INTERCEPT and REGR_R2“When this function is called as a window function, it does not support: An ORDER BY clause within the OVER clause.”
↩︎ A linear trend in plain SQL with REGR_SLOPE, REGR_INTERCEPT and REGR_R2“Note the order of the arguments; the dependent variable is first.”
↩︎ Exam trap 1 - 2.
“Returns the intercept of the univariate linear regression line for non-null pairs in a group.”
↩︎ A linear trend in plain SQL with REGR_SLOPE, REGR_INTERCEPT and REGR_R2 - 3.
“Returns the coefficient of determination for non-null pairs in a group.”
↩︎ A linear trend in plain SQL with REGR_SLOPE, REGR_INTERCEPT and REGR_R2 - 4.
“Forecasting uses a machine learning algorithm that predicts future numeric data from historical time series data.”
↩︎ Training a FORECAST model and calling it“model training can handle real-world data that has missing, duplicate, or misaligned time steps.”
↩︎ Training a FORECAST model and calling it“Note that the model has inferred the interval between timestamps from the training data.”
↩︎ Training a FORECAST model and calling it“the prediction interval (LOWER_BOUND, UPPER_BOUND) is the same as the FORECAST value.”
↩︎ Training a FORECAST model and calling it“As shown in the example above, when calling the method, omit the CALL command.”
↩︎ Training a FORECAST model and calling it“To create a forecasting model for multiple series at once, use the series_colname parameter.”
↩︎ One model for many series with SERIES_COLNAME“This example uses a single time series (that is, all the rows are part of a single series)”
↩︎ One model for many series with SERIES_COLNAME“Specifying one series with the FORECAST method is more efficient than filtering the results of a multi-series forecast”
↩︎ One model for many series with SERIES_COLNAME“additional columns in the input data are assumed to be features for use in training.”
↩︎ Forecasting with exogenous features“Instead, the timestamps of the forecast come from the v2_forecast view.”
↩︎ Forecasting with exogenous features“By default, the forecasting function evaluates all models it trains using a method called cross-validation.”
↩︎ Judging a forecast model: evaluation metrics, feature importance and logs“The total number of training rows must be equal to or greater than (n_splits * test_size) + gap.”
↩︎ Judging a forecast model: evaluation metrics, feature importance and logs“These feature importance scores are then normalized to values between 0 and 1 so that their sum is 1.”
↩︎ Judging a forecast model: evaluation metrics, feature importance and logs“SELECT * FROM TABLE(my_model!FORECAST(FORECASTING_PERIODS => 7));”
↩︎ Exam trap 2“In this variation of the FORECAST method, you do not specify the number of timestamps to predict.”
↩︎ Exam trap 3“create a new column that combines these values, and specify that as the series column.”
↩︎ Checkpoint“To generate forecasts with this model, you must provide future values for the features to the model”
↩︎ Prediction“Assess your model’s accuracy. Understand the relative importance of the features the model was trained on. Debug training errors.”
↩︎ Checkpoint - 5.
“The <model_name>!SHOW_TRAINING_LOGS method provides error messages for any time series whose models failed to fit.”
↩︎ Judging a forecast model: evaluation metrics, feature importance and logs“You use CREATE SNOWFLAKE.ML.FORECAST to create and train the forecasting model, then use the model’s <model_name>!FORECAST method to produce forecasts.”
↩︎ Key concept - 6.https://docs.snowflake.com/en/sql-reference/classes/forecast/methods/explain_feature_importanceOfficial docs
“user_provided: Feature data provided by the user.”
↩︎ Judging a forecast model: evaluation metrics, feature importance and logs
Also cited
“In these instances, the aggregate function ignores a row if any individual column is NULL.”
↩︎ Checkpoint