-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
i317814
committed
Nov 22, 2022
1 parent
65ff8e4
commit 9d7f935
Showing
53 changed files
with
1,106 additions
and
44 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
sql/procedure/apl_samples/binary-classification/apl_test_generic_debrief.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
-- @required(hanaMinimumVersion,2.0.32) | ||
-- ================================================================ | ||
connect USER_APL password Password1; | ||
SET SESSION 'APL_CACHE_SCHEMA' = 'APL_CACHE'; | ||
|
||
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_EXTENDED"; | ||
declare test_config "SAP_PA_APL"."sap.pa.apl.base::BASE.T.OPERATION_CONFIG_EXTENDED"; | ||
declare debrief_config "SAP_PA_APL"."sap.pa.apl.base::BASE.T.OPERATION_CONFIG_EXTENDED"; | ||
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 out_model "SAP_PA_APL"."sap.pa.apl.base::BASE.T.MODEL_BIN_OID"; | ||
declare out_model_test "SAP_PA_APL"."sap.pa.apl.base::BASE.T.MODEL_BIN_OID"; | ||
declare out_log "SAP_PA_APL"."sap.pa.apl.base::BASE.T.OPERATION_LOG"; | ||
declare out_sum "SAP_PA_APL"."sap.pa.apl.base::BASE.T.SUMMARY"; | ||
declare out_debrief_metric "SAP_PA_APL"."sap.pa.apl.base::BASE.T.DEBRIEF_METRIC_OID"; | ||
declare out_debrief_property "SAP_PA_APL"."sap.pa.apl.base::BASE.T.DEBRIEF_PROPERTY_OID"; | ||
|
||
:header.insert(('Oid', '#42')); | ||
:header.insert(('LogLevel', '8')); | ||
:header.insert(('ModelFormat', 'bin')); | ||
|
||
:config.insert(('APL/ModelType', 'binary classification',null)); | ||
:config.insert(('APL/MaxIterations', '100',null)); -- default value: 1000 | ||
:config.insert(('APL/EarlyStoppingPatience', '10',null)); -- default value: 10 | ||
:config.insert(('APL/LearningRate', '.08',null)); -- default value: 0.1 | ||
:config.insert(('APL/CorrelationsMaxKept', '10',null)); -- default value: 1024 | ||
:config.insert(('APL/CorrelationsLowerBound', '.99',null)); -- default value: 0.50 | ||
:config.insert(('APL/EvalMetric', 'LogLoss,AUC',null)); | ||
|
||
:config.insert(('APL/VariableAutoSelection', 'true',null)); | ||
:config.insert(('APL/VariableSelectionPercentageOfContributionKeptByStep', '0.97',null)); -- default value: 0.95 | ||
:config.insert(('APL/VariableSelectionQualityBar', '0.02',null)); -- default value: 0.01 | ||
:config.insert(('APL/VariableSelectionMaxIterations', '4',null)); -- default value: 2 | ||
|
||
:var_role.insert(('class', 'target', null, null, null)); | ||
|
||
"SAP_PA_APL"."sap.pa.apl.base::CREATE_MODEL_AND_TRAIN"(:header, :config, :var_desc,:var_role, 'APL_SAMPLES','ADULT01',out_model,out_log,out_sum, out_indicators); | ||
"SAP_PA_APL"."sap.pa.apl.base::TEST_MODEL"(:header, :out_model, :test_config,'APL_SAMPLES','ADULT01', out_model_test, out_log, out_indicators); | ||
"SAP_PA_APL"."sap.pa.apl.base::GET_MODEL_DEBRIEF"(:header, :out_model_test, :debrief_config, out_debrief_metric, out_debrief_property, out_debrief_summary); | ||
|
||
-- Dump Statistics Report | ||
select * from "SAP_PA_APL"."sap.pa.apl.debrief.report::Statistics_Partition"(:out_debrief_property, :out_debrief_metric); | ||
|
||
-- Dump Statistics Binary Target | ||
select * from "SAP_PA_APL"."sap.pa.apl.debrief.report::BinaryTarget_CurveRoc"(:out_debrief_property, :out_debrief_metric); | ||
select * from "SAP_PA_APL"."sap.pa.apl.debrief.report::BinaryTarget_CurveLift"(:out_debrief_property, :out_debrief_metric); | ||
select * from "SAP_PA_APL"."sap.pa.apl.debrief.report::BinaryTarget_CurveGain"(:out_debrief_property, :out_debrief_metric); | ||
END; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
sql/procedure/apl_samples/binary-classification/segmented_test_model.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
-- @required(hanaMinimumVersion,2.0.40) | ||
-- ================================================================ | ||
-- APL_AREA, APPLY_MODEL, using a binary format for the model | ||
-- This script demonstrates the application of the binary classification model | ||
-- to predict the target and to get the individual contributions per input | ||
-- | ||
-- Assumption 1: The users & privileges have been created & granted (see apl_admin_ex.sql). | ||
-- Assumption 2: There's a valid trained model (created by APL) in the MODEL_TRAIN_BIN table. | ||
-- @depend(segmented_create_train.sql) | ||
connect USER_APL password Password1; | ||
SET SESSION 'APL_CACHE_SCHEMA' = 'APL_CACHE'; | ||
|
||
drop table TEST_INDICATORS; | ||
create table TEST_INDICATORS like "SAP_PA_APL"."sap.pa.apl.base::BASE.T.INDICATORS"; | ||
|
||
drop table TEST_MODEL_BIN; | ||
create table TEST_MODEL_BIN like "SAP_PA_APL"."sap.pa.apl.base::BASE.T.MODEL_BIN_OID"; | ||
|
||
drop table TEST_OPERATION_LOG; | ||
create table TEST_OPERATION_LOG like "SAP_PA_APL"."sap.pa.apl.base::BASE.T.OPERATION_LOG"; | ||
|
||
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_EXTENDED"; | ||
declare model "SAP_PA_APL"."sap.pa.apl.base::BASE.T.MODEL_BIN_OID"; | ||
declare out_model "SAP_PA_APL"."sap.pa.apl.base::BASE.T.MODEL_BIN_OID"; | ||
declare out_log "SAP_PA_APL"."sap.pa.apl.base::BASE.T.OPERATION_LOG"; | ||
declare out_indicators "SAP_PA_APL"."sap.pa.apl.base::BASE.T.INDICATORS"; | ||
|
||
model = select * from MODEL_TRAIN_BIN; | ||
|
||
:header.insert(('Oid', '#42')); | ||
:header.insert(('LogLevel', '2')); | ||
:header.insert(('MaxTasks', '2')); -- define nb parallel tasks to use for train | ||
|
||
:config.insert(('APL/SegmentColumnName', 'Seg',null)); -- define the column used as the segmentation colum | ||
|
||
"SAP_PA_APL"."sap.pa.apl.base::TEST_MODEL"(:header, :model, :config,'USER_APL','ADULT01_SORTED', out_model, out_log, out_indicators); | ||
|
||
-- store result into table | ||
insert into TEST_INDICATORS select * from :out_indicators; | ||
insert into TEST_MODEL_BIN select * from :out_model; | ||
insert into TEST_OPERATION_LOG select * from :out_log; | ||
END; | ||
|
||
select * from TEST_INDICATORS; | ||
select * from TEST_MODEL_BIN; | ||
select * from TEST_OPERATION_LOG; |
69 changes: 69 additions & 0 deletions
69
sql/procedure/apl_samples/binary-classification/segmented_test_model_debrief.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
-- @required(hanaMinimumVersion,2.0.40) | ||
-- ================================================================ | ||
-- APL_AREA, APPLY_MODEL, using a binary format for the model | ||
-- This script demonstrates the application of the binary classification model | ||
-- to predict the target and to get the individual contributions per input | ||
-- | ||
-- Assumption 1: The users & privileges have been created & granted (see apl_admin_ex.sql). | ||
-- Assumption 2: There's a valid trained model (created by APL) in the MODEL_TRAIN_BIN table. | ||
-- @depend(segmented_create_train.sql) | ||
connect USER_APL password Password1; | ||
SET SESSION 'APL_CACHE_SCHEMA' = 'APL_CACHE'; | ||
|
||
drop table TEST_SUMMARY; | ||
create table TEST_SUMMARY like "SAP_PA_APL"."sap.pa.apl.base::BASE.T.SUMMARY"; | ||
|
||
drop table TEST_METRIC; | ||
create table TEST_METRIC like "SAP_PA_APL"."sap.pa.apl.base::BASE.T.DEBRIEF_METRIC_OID"; | ||
|
||
drop table TEST_PROPERTY; | ||
create table TEST_PROPERTY like "SAP_PA_APL"."sap.pa.apl.base::BASE.T.DEBRIEF_PROPERTY_OID"; | ||
|
||
drop table TEST_MODEL_BIN; | ||
create table TEST_MODEL_BIN like "SAP_PA_APL"."sap.pa.apl.base::BASE.T.MODEL_BIN_OID"; | ||
|
||
drop table TEST_OPERATION_LOG; | ||
create table TEST_OPERATION_LOG like "SAP_PA_APL"."sap.pa.apl.base::BASE.T.OPERATION_LOG"; | ||
|
||
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_EXTENDED"; | ||
declare model "SAP_PA_APL"."sap.pa.apl.base::BASE.T.MODEL_BIN_OID"; | ||
declare out_model "SAP_PA_APL"."sap.pa.apl.base::BASE.T.MODEL_BIN_OID"; | ||
declare out_log "SAP_PA_APL"."sap.pa.apl.base::BASE.T.OPERATION_LOG"; | ||
declare out_summary "SAP_PA_APL"."sap.pa.apl.base::BASE.T.SUMMARY"; | ||
declare out_metric "SAP_PA_APL"."sap.pa.apl.base::BASE.T.DEBRIEF_METRIC_OID"; | ||
declare out_property "SAP_PA_APL"."sap.pa.apl.base::BASE.T.DEBRIEF_PROPERTY_OID"; | ||
|
||
model = select * from MODEL_TRAIN_BIN; | ||
|
||
:header.insert(('Oid', '#42')); | ||
:header.insert(('LogLevel', '2')); | ||
:header.insert(('MaxTasks', '2')); -- define nb parallel tasks to use for train | ||
|
||
:config.insert(('APL/SegmentColumnName', 'Seg',null)); -- define the column used as the segmentation colum | ||
|
||
"SAP_PA_APL"."sap.pa.apl.base::TEST_MODEL_DEBRIEF"(:header, :model, :config,'USER_APL','ADULT01_SORTED', out_model, out_log, out_summary, out_metric,out_property); | ||
|
||
-- store result into table | ||
insert into TEST_PROPERTY select * from :out_property; | ||
insert into TEST_METRIC select * from :out_metric; | ||
insert into TEST_SUMMARY select * from :out_summary; | ||
insert into TEST_MODEL_BIN select * from :out_model; | ||
insert into TEST_OPERATION_LOG select * from :out_log; | ||
END; | ||
|
||
select * from TEST_MODEL_BIN; | ||
select * from TEST_OPERATION_LOG; | ||
|
||
-- Nb trained models | ||
select count(*) from TEST_SUMMARY where "KEY" = 'AplTaskElapsedTime'; | ||
|
||
-- Average time to train a segment | ||
select AVG(to_double("VALUE")) from TEST_SUMMARY where "KEY" = 'AplTaskElapsedTime'; | ||
|
||
-- Total time | ||
select * from TEST_SUMMARY where "KEY" = 'AplTotalElapsedTime'; | ||
|
||
-- Debrief all models by segment | ||
select * from "SAP_PA_APL"."sap.pa.apl.debrief.report::ClassificationRegression_Performance"(TEST_PROPERTY, TEST_METRIC); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
sql/procedure/apl_samples/classification_regression/segmented_test_mode_reg.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
-- @required(hanaMinimumVersion,2.0.40) | ||
-- ================================================================ | ||
-- APL_AREA, APPLY_MODEL, using a binary format for the model | ||
-- This script demonstrates the application of the binary classification model | ||
-- to predict the target and to get the individual contributions per input | ||
-- | ||
-- Assumption 1: The users & privileges have been created & granted (see apl_admin_ex.sql). | ||
-- Assumption 2: There's a valid trained model (created by APL) in the MODEL_TRAIN_BIN table. | ||
-- @depend(segmented_create_train_class.sql) | ||
connect USER_APL password Password1; | ||
SET SESSION 'APL_CACHE_SCHEMA' = 'APL_CACHE'; | ||
|
||
drop table TEST_INDICATORS; | ||
create table TEST_INDICATORS like "SAP_PA_APL"."sap.pa.apl.base::BASE.T.INDICATORS"; | ||
|
||
drop table TEST_MODEL_BIN; | ||
create table TEST_MODEL_BIN like "SAP_PA_APL"."sap.pa.apl.base::BASE.T.MODEL_BIN_OID"; | ||
|
||
drop table TEST_OPERATION_LOG; | ||
create table TEST_OPERATION_LOG like "SAP_PA_APL"."sap.pa.apl.base::BASE.T.OPERATION_LOG"; | ||
|
||
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_EXTENDED"; | ||
declare model "SAP_PA_APL"."sap.pa.apl.base::BASE.T.MODEL_BIN_OID"; | ||
declare out_model "SAP_PA_APL"."sap.pa.apl.base::BASE.T.MODEL_BIN_OID"; | ||
declare out_log "SAP_PA_APL"."sap.pa.apl.base::BASE.T.OPERATION_LOG"; | ||
declare out_indicators "SAP_PA_APL"."sap.pa.apl.base::BASE.T.INDICATORS"; | ||
|
||
model = select * from MODEL_TRAIN_BIN; | ||
|
||
:header.insert(('Oid', '#42')); | ||
:header.insert(('LogLevel', '2')); | ||
:header.insert(('MaxTasks', '2')); -- define nb parallel tasks to use for train | ||
|
||
:config.insert(('APL/SegmentColumnName', 'Seg',null)); -- define the column used as the segmentation colum | ||
|
||
"SAP_PA_APL"."sap.pa.apl.base::TEST_MODEL"(:header, :model, :config,'USER_APL','ADULT01_SORTED', out_model, out_log, out_indicators); | ||
|
||
-- store result into table | ||
insert into TEST_INDICATORS select * from :out_indicators; | ||
insert into TEST_MODEL_BIN select * from :out_model; | ||
insert into TEST_OPERATION_LOG select * from :out_log; | ||
END; | ||
|
||
select * from TEST_INDICATORS; | ||
select * from TEST_MODEL_BIN; | ||
select * from TEST_OPERATION_LOG; |
Oops, something went wrong.