Quantcast
Channel: SCN : All Content - SAP BusinessObjects Predictive Analytics
Viewing all articles
Browse latest Browse all 836

How can i run APRIORIRULE algorithm for different markets

$
0
0

Hi all,

 

According to my research i found the below code for basket analysis.

 

 

APRIORIRULE

SETSCHEMA TEST;

 

-- cleanup

DROPTYPE PAL_T_AP_DATA;

DROPTYPE PAL_T_AP_PARAMS;

DROPTYPE PAL_T_AP_RULES;

DROPTYPE PAL_T_AP_PMML;

DROPTABLE PAL_AP_SIGNATURE;

CALLSYSTEM.AFL_WRAPPER_ERASER ('PAL_AP');

DROPTABLE AP_RULES;

DROPTABLE AP_PMML;

 

-- PAL setup

CREATETYPE PAL_T_AP_DATA ASTABLE (ORDERID INTEGER, PRODUCTID INTEGER);

CREATETYPE PAL_T_AP_PARAMS ASTABLE (NAME VARCHAR(60), INTARGS INTEGER, DOUBLEARGS DOUBLE, STRINGARGS VARCHAR (100));

CREATETYPE PAL_T_AP_RULES ASTABLE (PRERULE VARCHAR(500), POSTRULE VARCHAR(500), SUPPORT DOUBLE, CONFIDENCE DOUBLE, LIFT DOUBLE);

CREATETYPE PAL_T_AP_PMML ASTABLE (ID INTEGER, PMMLMODEL VARCHAR(5000));

 

CREATECOLUMNTABLE PAL_AP_SIGNATURE (ID INTEGER, TYPENAME VARCHAR(1000), DIRECTION VARCHAR(100));

INSERTINTO PAL_AP_SIGNATURE VALUES (1, 'TEST.PAL_T_AP_DATA', 'in');

INSERTINTO PAL_AP_SIGNATURE VALUES (2, 'TEST.PAL_T_AP_PARAMS', 'in');

INSERTINTO PAL_AP_SIGNATURE VALUES (3, 'TEST.PAL_T_AP_RULES', 'out');

INSERTINTO PAL_AP_SIGNATURE VALUES (4, 'TEST.PAL_T_AP_PMML', 'out');

 

 

CALLSYSTEM.AFL_WRAPPER_GENERATOR ('PAL_AP', 'AFLPAL', 'APRIORIRULE', PAL_AP_SIGNATURE);

 

DROPVIEW V_AP_DATA;

-- app setup

CREATEVIEW V_AP_DATA AS

 

 

SELECTORDERID,PRODUCTID FROM MARKETSALES;

 

 

CREATECOLUMNTABLE AP_RULES LIKE PAL_T_AP_RULES;

CREATECOLUMNTABLE AP_PMML LIKE PAL_T_AP_PMML;

 

-- app runtime

DROPTABLE #AP_PARAMS;

CREATELOCALTEMPORARYCOLUMNTABLE #AP_PARAMS LIKE PAL_T_AP_PARAMS;

INSERTINTO #AP_PARAMS VALUES ('THREAD_NUMBER', 1, null, null);

INSERTINTO #AP_PARAMS VALUES ('MIN_SUPPORT', null, 0.1, null);

INSERTINTO #AP_PARAMS VALUES ('MIN_CONFIDENCE', null, 0.8, null);

--INSERT INTO #AP_PARAMS VALUES ('MIN_LIFT', null, 1.0, null);

INSERTINTO #AP_PARAMS VALUES ('MAX_ITEM_LENGTH', 5, null, null);

--INSERT INTO #AP_PARAMS VALUES ('MAX_CONSEQUENT', 1, null, null);

INSERTINTO #AP_PARAMS VALUES ('PMML_EXPORT', 0, null, null);

 

-- NEW FROM SPS08

INSERTINTO #AP_PARAMS VALUES ('IS_USE_PREFIX_TREE', 0, null, null); -- 0: no, 1: yes

--INSERT INTO #AP_PARAMS VALUES ('LHS_RESTRICT', null, null, '37');

--INSERT INTO #AP_PARAMS VALUES ('LHS_RESTRICT', null, null, '43');

--INSERT INTO #AP_PARAMS VALUES ('RHS_IS_COMPLEMENTARY_LHS', 0, null, null); -- 0: no, 1: yes

--INSERT INTO #AP_PARAMS VALUES ('RHS_RESTRICT', null, null, '10');

--INSERT INTO #AP_PARAMS VALUES ('RHS_RESTRICT', null, null, '11');

--INSERT INTO #AP_PARAMS VALUES ('LHS_IS_COMPLEMENTARY_RHS', 0, null, null); -- 0: no, 1: yes

 

TRUNCATETABLE AP_RULES;

TRUNCATETABLE AP_PMML;

 

CALL _SYS_AFL.PAL_AP (V_AP_DATA, #AP_PARAMS, AP_RULES, AP_PMML) WITH OVERVIEW;

 

--SELECT * FROM V_AP_DATA;

SELECT * FROM AP_RULES ORDERBY PRERULE, POSTRULE;

--SELECT * FROM AP_PMML;

 

 

 

I was searching a way to do this for different markets. I mean in MARKETSALES table lets say i have, marketid, orderid and productid. If i run the above code the result should be for all markets.

 

So, 1 solution is using SELECTORDERID,PRODUCTID FROM MARKETSALES WHERE marketid=?; But in this way, i have to run the code for all markets. And save their data manually. Is there any way to do it automatically for different markets?

 

And also after i finish the code i will publish it to lumira. So that for the below table i think that i should also add the parameter marketid for seperating the basket analysis. So that my user can filter by marketid and choose the post/pre rule for creating the charts using lumira.

 

PAL_T_AP_RULES ASTABLE (MARKETID INTEGER,PRERULE VARCHAR(500), POSTRULE VARCHAR(500), SUPPORT DOUBLE, CONFIDENCE DOUBLE, LIFT DOUBLE);


Any idea about this issue?


Viewing all articles
Browse latest Browse all 836

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>