Skip to Content

We have seen in the first part how to create a recommendation model using an SAP HANA information view and asking the user to choose a country. However, more work needs to be done since the business requires us to define a recommendation model for each country. In order to avoid doing the work manually through the user interface, we are going to use a KxShell script. The nice thing about KxShell scripts is that even if you don’t know how to write them, you can ask SAP Predictive Analytics to produce them for you. In the summary screen (the step just before the generation of the model), you can click on: Export KxShell Script.

0_KXSHELL-EXPORT-BEFORE_GENERATE.png

You need to indicate the folder where to store the script and the name of the kxs file.

1_KXSHELL-SAVE.png

The script can be run interactively. Our SAP Predictive Analytics desktop version is installed on a Windows machine. With the cd command we change our working directory to CPP (the name of the folder where the kxshell.exe file is found).


cd C:\Program Files\SAP Predictive Analytics\Desktop 2.3\Automated\EXE\Clients\CPP


We then run the script with country as an argument having the value: Germany.


kxshell C:\ADV_ANALYTICS\RECO_FOR_A_COUNTRY.kxs -DEVENTS_HVIEW_VAR_1_ANSW_1_VAL1=”Germany”


To obtain the name of the SAP HANA country variable, we looked at the automatically generated script.


# Declaring arguments/variables used in the Events data set (ANV_INVOICES).

# ## Hana view Variable 1 : VAR_COUNTRY (Country)

default EVENTS_HVIEW_VAR_1_ANSW_1_VAL1 “France”

default EVENTS_HVIEW_VAR_1_ANSW_1_OP “=”


In fact this script must be modified a little bit before it can be used. We replaced the strings $STORE_USER and $STORE_PWD with the SAP HANA user and password.


#Declaring the ‘EVENTS’ store and space

default EVENTS_STORE_TYPE “Kxen.ODBCStore”

default EVENTS_STORE_NAME “A_HANA_SERVER/Content/ADV_SAMPLES”

default EVENTS_STORE_USER “DATA_SOURCES”

default EVENTS_STORE_PWD “drowssap_elbakaerbnu”


Perhaps you don’t want to leave the password in the KxShell script, in which case you need to use this syntax:


default EVENTS_STORE_PWD $(STORE_PWD)


The password must then appear as an argument in the command.


kxshell C:\ADV_ANALYTICS\RECO_FOR_A_COUNTRY.kxs -DEVENTS_HVIEW_VAR_1_ANSW_1_VAL1=”Germany” -DSTORE_PWD=”drowssap_elbakaerbnu”


Another section that we modified has to do with saving the model.


default MODEL_SAVE_STORE_TYPE “Kxen.FileStore”

default MODEL_SAVE_STORE_NAME “C:\ADV_ANALYTICS\RECO_MODELS”

default MODEL_SAVE_STORE_USER “”

default MODEL_SAVE_STORE_PWD “”

default MODEL_SAVE_NAME “ANV_INVOICES_$(EVENTS_HVIEW_VAR_1_ANSW_1_VAL1)”

default MODEL_SAVE_SPACE “ANV_INVOICES_$(EVENTS_HVIEW_VAR_1_ANSW_1_VAL1).kxen”


Note that we made the parameter related to the country variable part of the model name.

So far we’ve run our KxShell script in interactive mode, which is useful for adjusting and testing the script. Now that it’s working properly, we will switch to batch mode. We prepared a bat file with two lines in it.


“C:\Program Files\SAP Predictive Analytics\Desktop 2.3\Automated\EXE\Clients\CPP\kxshell.exe” C:\ADV_ANALYTICS\RECO_FOR_A_COUNTRY.kxs -DEVENTS_HVIEW_VAR_1_ANSW_1_VAL1=”Spain” > C:\ADV_ANALYTICS\log_create_reco_spain.txt

“C:\Program Files\SAP Predictive Analytics\Desktop 2.3\Automated\EXE\Clients\CPP\kxshell.exe” C:\ADV_ANALYTICS\RECO_FOR_A_COUNTRY.kxs -DEVENTS_HVIEW_VAR_1_ANSW_1_VAL1=”UK” > C:\ADV_ANALYTICS\log_create_reco_uk.txt


We redirect the output of the command to a text file in order to keep a detailed trace of the recommendation model generation.

After running the batch file, we can see the models from the desktop application.

A_Load.png


B_Open_Germany.png

The models created with a script are ready to be used for recommending products to customers.

Note that using a KxShell script for automating the creation of multiple models is not specific to recommendation. It is applicable to other data mining functions like classification, regression or times series forecasting. 


Marc



To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

Leave a Reply