How to use Python ML on SAP BTP into S/4HANA Utilities to predict customer data
Introduction and Motivation
There are already several blog posts on the topic of “Deployment of Python-ML Service on SAP BTP”. Based on these posts, we want to describe a concrete integration scenario and thus encapsulate the complex topic of ML in an actual use case and make it ” touchable”.
Customer service processes such as meter reading, product advice, change or move-in are lived as mass processes and require manual processing to a large extent. For this very reason, it makes sense to support these processes with ML in order to increase the degree of automation and to support the agent in his decision-making and thus accelerate the process.
In the following, we will show you how easy it is to implement a forecast of the estimated annual consumption with the help of SAP BTP and Python (bring your own language). This is an exemplary use case. It demonstrates in particular how easily the existing IT architecture can be extended to include meaningful use cases with the help of cloud components.
The customer contacts their utility supplier to sign up for a new electricity contract with a given delivery start date. The agent at the service center asks the customer for his estimated annual consumption so that he can inform the customer about possible costs. Unfortunately, the customer does not have an estimate because more people will be living in his household in the future, he is moving into a single-family home for the first time, or he wants to use an air-source heat pump, with which he has no consumer experience. To speed up the process, the use of ML can help to predict the consumption based on these parameters (mentioned as examples).
In the backend, an S4/HANA Utilities is used, in which customer service processes are handled using Customer Engagement (new customer service interface as successor to CIC0; see also post by Tammy Powlas https://blogs.sap.com/2020/06/29/sap-s-4hana-utilities-for-customer-engagement-summary/). We are implementing the described prediction capability on the SAP BTP using bring your own language. Therfore we use scikit-learn (version 0.24) as a machine learning library for Python. The trained model is saved as a PKL file, which can be called in a Python Flask app.
Short Implementation Guide
Python ml service implementation
Based on existing anonymized customer data, which contains both the desired parameters (age, place of residence, number of persons in the household, etc.) and the target variable (initial annual consumption), the ML model is trained in Python. To select appropriate features, the data set should be analyzed. Based on the preliminary analysis, a suitable model is selected. In this use case, we used a Random Forrest model from the Scikit-Learn library. The trained model is then saved as a PKL file via
pkl_filename = "pickle_model.pkl" with open(pkl_filename, 'wb') as file: pickle.dump(model, file)
To be able to call the model via the BTP, a second file app.py is required. In this file the model is called with the appropriate parameters and returns the forecast result as a json file.
Deploy python ML service on SAP BTP
Using the Cloud Foundry Command Line Interface, the Python app was deployed to our BTP Cloud Foundry Instance. The service can be started and invoked directly after pushing to the instance. The steps in detail are:
- Push your python App to SAP BTP by using a specific manifest.yml file
- After uploading and your app should be started
- That’s the BTP implementation, you can now use your python ML-service
Let us give it a try by using your application route and your needed variables (e.g. via Postman):
As expected, we received a predicted consumption according to our given parameters.
SAP ABAP Backend Integration / Implementation
For the backend ABAP call we have encapsulated the API in a simple ABAP class. Which calls the service based on the SAP standard implementation class CL_HTTP_CLIENT.
This call can be included in any / meaningful customer service processes to support the agent in his work and reduce the processing time. In our use case, the function was placed in the move-in process:
The agent is offered a predicted annual consumption, which is determined based on various parameters of the customer, such as the number of people living in the household, age, place of residence, gender or energy sector.
Conclusion & Ideas
With the help of ML-based predictions and SAP BTP, processes can be significantly simplified for the employee. Currently, we are working on the following:
- Continuous learning
- Extension of the model with additional features
- Add SAP Integration Suite Content to integration backend process with python-service
- Integration with other customer service processes
We will be happy to give you an update when we have something new. We hope that we were able to show you the combination of a ML use cases and mass processes in a comprehensible way and we are looking forward to your feedback!
Finally, thanks again to my colleague @jacqueline_cl for the great support especially around machine learning.
Awesome Blog with lot of future potential.
If possible please share the Code git repository .
Thanks and Regards,
Hi Alok @SAP ,
you find our coding in repository: https://github.com/klotzjo/sap-python-ml
Thanks Jonathan . Any real use case in SAP where we can use ML Model .
Please provide some real scenario . I want to work on them .