Saturday, 2 July 2016

Predictive analytics using SAP Design Studio and SAP HANA – Part 2

In part 1, we discussed the 101 of predictive analytics in SAP HANA using SAP HANA PAL and HANA flowgraph modelling. The drag and drop interface allows us to focus on the analysis without spending too much time writing out complex SQL scripts.

In this blog, we will understand how we can integrate flowgraphs with SAP Design Studio and provide a readily consumable output to the decision makers.

Extending our example from the previous blog, we would like to select different store and product combinations, to be able to view the sales forecast at a granular level. This kind of analysis will help in inventory planning, promotional offers for low selling products and so on. We would also like to choose the number of periods of forecast as well as be able to modify the forecast parameters to ensure a good fit.

Image-1: Visualizing SAP HANA Flowgraph output using SAP Design Studio

Predictive analytics using SAP Design Studio and SAP HANA – Part 2

Above is a sample application built using SAP Design Studio to present our case, with text inputs, dropdowns and radio buttons to pass the parameters. This application must be able to interact with the predictive algorithms running on HANA and pass the various parameters to the Prediction model.

Solution -1

A simple approach to do this would be to include a filter node in the flow graph created in part 1 and iterate the steps over all store and product combinations. We can then write the results back to a table and consume it in Design Studio using a Calculation View. This approach can be tedious and also has to be scheduled to run during downtime hours. Also, this would apply the same model parameters to all the store and product combinations which may not yield the best of results.

Image-2: Using filter node to select a particular store and product

Predictive analytics using SAP Design Studio and SAP HANA – Part 2

Solution2- Doing things on the fly

To visualize something in SAP Design Studio, it should be a column view (from SAP HANA perspective). From our sample application shown above, it is clear that we would need to pass the various parameters as variable values to this column view. The drawbacks of solution1 tells us that this column view cannot be built on just tables as we would like to run the prediction algorithm and the flow graph procedure each time there is a change in the parameters in the front-end. To achieve this, we create a scripted calculation view in HANA and call the flow graph procedure within it. The problem does not end there. Each time there is change to the parameters, the meta-data table, where model parameters are stored, needs to be updated. Then again, write operations are not permitted within scripted views. To work around this, we tweak the flow graph procedure to replace corresponding parameter values at runtime using a simple case statement within the select statement which picks up values from the parameter table.

Image-3: Modified Select statement on the model parameter table

Predictive analytics using SAP Design Studio and SAP HANA – Part 2

Image-4: Actual Select statement on the model parameter table

Predictive analytics using SAP Design Studio and SAP HANA – Part 2
Lastly, to change the dimension members (Store and Product) dynamically, we create a custom procedure with two scalar input parameters for Store and Product respectively and replace the  static filter during the pre-process of data in the flowgraph.

Image-5: Modified Dynamic Dimension Filter

Predictive analytics using SAP Design Studio and SAP HANA – Part 2

Image-6: Flowgraph – Design Studio integration workflow

Predictive analytics using SAP Design Studio and SAP HANA – Part 2

Finally, this column view is consumable in SAP Design Studio and we can select model parameters as well as dimension parameters on the fly and visualize the predictions accordingly.

This approach can be further extended to other complex predictive algorithms such as classification, regression and decision trees with great visualizations using SAP Design Studio. This can also be extended to other visualization and data discovery tools like SAP Lumira and WebI enabling decision makers with the power of predictive analytics.

Source: scn.sap.com

No comments:

Post a Comment