Can you predict the future? No? Well, Snowflake kinda can! How? Well it’s those Cortex functions that everyone keeps going on about.
This week we’ll be using one of their ML functions.
Your job is to get the training data:
CREATE STAGE IF NOT EXISTS frosty_aws_stage
URL = 's3://frostyfridaychallenges/';
CREATE OR REPLACE TABLE WEEK_90 AS
SELECT
$1::TIMESTAMP_NTZ AS SALE_DATE,
$2::INT AS PRODUCT_ID,
$3::INT AS QUANTITY_SOLD,
$4::INT AS UNIT_PRICE,
$5/100::FLOAT AS TAX_PCT,
$6/100::FLOAT AS DCT_PCT
FROM @FROSTY_AWS_STAGE/challenge_90
WHERE $1 != 'Date';
And see what Snowflake has to say forecasting-wise about the below:
CREATE OR REPLACE TABLE WEEK_90_F LIKE WEEK_90;
ALTER TABLE WEEK_90_F DROP COLUMN QUANTITY_SOLD;
INSERT INTO WEEK_90_F VALUES
(TO_TIMESTAMP_NTZ('2023-10-29'), 1000, 450, 0.1, 0.02),
(TO_TIMESTAMP_NTZ('2023-10-29'), 1001, 150, 0.15, 0.02),
(TO_TIMESTAMP_NTZ('2023-10-29'), 1002, 100, 0.13, 0.18),
(TO_TIMESTAMP_NTZ('2023-10-29'), 1003, 170, 0.11, 0.03),
(TO_TIMESTAMP_NTZ('2023-10-29'), 1004, 300, 0.04, 0.03);
Your output should look like the below:
Happy forecasting!
darko says
Cool challenge! First time using this ML function. It took me 3-4 trials and errors to get to the right solution. Luckily, the error messages in Snowflake simplify navigating the documentation.
mferle says
Good to know I can do this one as I’ll be presenting it at Summit!
ChrisHastie says
This approach to forecasting is so much easier than playing about with your own UDTF and Python libaries!