Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
marc_daniau
Advisor
Advisor

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.

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

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.


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



1 Comment