from hana_ml import dataframe as hd
conn = hd.ConnectionContext(userkey='MLMDA_KEY')
series_in = conn.table('SALES', schema='APL_SAMPLES')
series_in.tail(6).collect()
from hana_ml.algorithms.apl.time_series import AutoTimeSeries
apl_model = AutoTimeSeries(time_column_name= 'Month', target= 'Amount', horizon= 3)
series_out = apl_model.fit_predict(data = series_in, build_report=True)
df = series_out.select(series_out.columns[0:5]).collect()
dict = {'ACTUAL': 'Actual',
'PREDICTED_1': 'Forecast',
'LOWER_INT_95PCT': 'Lower Limit',
'UPPER_INT_95PCT': 'Upper Limit' }
df.rename(columns=dict, inplace=True)
df.tail(6)
apl_model.generate_notebook_iframe_report()
-- Input Series sorted over time
create view TS_SORTED as select * from APL_SAMPLES.SALES order by "Month" asc;
--- Output Tables
create table FORECAST_OUT (
"Month" DATE,
"Amount" DOUBLE,
"kts_1" DOUBLE,
"kts_1Trend" DOUBLE,
"kts_1Cycles" DOUBLE,
"kts_1_lowerlimit_95%" DOUBLE,
"kts_1_upperlimit_95%" DOUBLE,
"kts_1ExtraPreds" DOUBLE,
"kts_1Fluctuations" DOUBLE,
"kts_1Residues" DOUBLE
);
create table OP_LOG like "SAP_PA_APL"."sap.pa.apl.base::BASE.T.OPERATION_LOG";
create table SUMMARY like "SAP_PA_APL"."sap.pa.apl.base::BASE.T.SUMMARY";
create table INDICATORS like "SAP_PA_APL"."sap.pa.apl.base::BASE.T.INDICATORS";
create table DEBRIEF_METRIC like "SAP_PA_APL"."sap.pa.apl.base::BASE.T.DEBRIEF_METRIC_OID";
create table DEBRIEF_PROPERTY like "SAP_PA_APL"."sap.pa.apl.base::BASE.T.DEBRIEF_PROPERTY_OID";
DO BEGIN
declare header "SAP_PA_APL"."sap.pa.apl.base::BASE.T.FUNCTION_HEADER";
declare config "SAP_PA_APL"."sap.pa.apl.base::BASE.T.OPERATION_CONFIG_DETAILED";
declare var_desc "SAP_PA_APL"."sap.pa.apl.base::BASE.T.VARIABLE_DESC_OID";
declare var_role "SAP_PA_APL"."sap.pa.apl.base::BASE.T.VARIABLE_ROLES_WITH_COMPOSITES_OID";
declare apl_log "SAP_PA_APL"."sap.pa.apl.base::BASE.T.OPERATION_LOG";
declare apl_sum "SAP_PA_APL"."sap.pa.apl.base::BASE.T.SUMMARY";
declare apl_indic "SAP_PA_APL"."sap.pa.apl.base::BASE.T.INDICATORS";
declare apl_metr "SAP_PA_APL"."sap.pa.apl.base::BASE.T.DEBRIEF_METRIC_OID";
declare apl_prop "SAP_PA_APL"."sap.pa.apl.base::BASE.T.DEBRIEF_PROPERTY_OID";
:header.insert(('Oid', 'Monthly Sales'));
:config.insert(('APL/Horizon', '3',null));
:config.insert(('APL/TimePointColumnName', 'Month',null));
:config.insert(('APL/LastTrainingTimePoint', '2018-08-01 00:00:00',null));
:config.insert(('APL/DecomposeInfluencers', 'true',null));
:config.insert(('APL/ApplyExtraMode', 'First Forecast with Stable Components and Residues and Error Bars',null));
:var_role.insert(('Month', 'input', null, null, null));
:var_role.insert(('Amount', 'target', null, null, null));
"SAP_PA_APL"."sap.pa.apl.base::FORECAST_AND_DEBRIEF"(
:header, :config, :var_desc, :var_role,
'USER_APL','TS_SORTED',
'USER_APL', 'FORECAST_OUT', apl_log, apl_sum, apl_indic, apl_metr, apl_prop);
insert into OP_LOG select * from :apl_log;
insert into SUMMARY select * from :apl_sum;
insert into INDICATORS select * from :apl_indic;
insert into DEBRIEF_METRIC select * from :apl_metr;
insert into DEBRIEF_PROPERTY select * from :apl_prop;
END;
create view DECOMPOSED_SERIES
("Time","Actual","Forecast","Trend","Cycles","Lower_Limit","Upper_Limit",
"Influencers","Fluctuations","Residuals") as
SELECT * FROM FORECAST_OUT ORDER BY 1;
SELECT "Time",
round("Actual",2) as "Actual",
round("Forecast",2) as "Forecast",
round("Trend",2) as "Trend",
round("Cycles",2) as "Cycles",
round("Influencers",2) as "Influencers",
round("Fluctuations",2) as "AR",
round("Residuals",2) as "Residuals"
FROM DECOMPOSED_SERIES ORDER BY 1;
select * from "SAP_PA_APL"."sap.pa.apl.debrief.report::TimeSeries_ModelOverview"
(USER_APL.DEBRIEF_PROPERTY, USER_APL.DEBRIEF_METRIC);
select * from "SAP_PA_APL"."sap.pa.apl.debrief.report::TimeSeries_Performance"
(USER_APL.DEBRIEF_PROPERTY, USER_APL.DEBRIEF_METRIC)
where "Partition" = 'Validation';
select * from "SAP_PA_APL"."sap.pa.apl.debrief.report::TimeSeries_Components"
(USER_APL.DEBRIEF_PROPERTY, USER_APL.DEBRIEF_METRIC);
select * from "SAP_PA_APL"."sap.pa.apl.debrief.report::TimeSeries_Decomposition"
(USER_APL.DEBRIEF_PROPERTY, USER_APL.DEBRIEF_METRIC)
order by 1, 2;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
17 | |
11 | |
10 | |
10 | |
9 | |
8 | |
7 | |
5 | |
5 | |
5 |