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: 
ChrisGruber
Advisor
Advisor

Introduction


 

Recently, SAP released SAP Predictive Analytics version 3.3.  Details on what is in this release can be found on the blog Announcing the release of SAP Predictive Analytics.  This release touts new support for Python.  Python is one of the most used languages for machine learning and is well equipped in numeric calculation.  Embedding predictive analytics libraries into a Python application is a natural progression for SAP Predictive Analytics.  In this article, we will take you through setting up the SAP Predictive Analytics Automated Analytics library with a Python environment on Windows.

Details on Python's use with data science and in general can be found in the links below:

https://towardsdatascience.com/what-is-the-best-programming-language-for-machine-learning-a745c156d6...

https://fossbytes.com/popular-top-programming-languages-machine-learning-data-science/

https://www.python.org/about/apps/

Note: You can also embed the SAP Predictive Analytics library into C++ and Java applications.

 

Business Benefits of Python


 

There are many web sites identifying the business benefits of Python. Here are some of my favorites which those of you working in data science may also appreciate.

 

  • Ease of use and readability

  • Large community support with many examples to draw upon

  • Large list of standard libraries, with many numeric and scientific libraries

  • No need for compilation

  • Internet of Things (IOT) applications are adopting Python

  • Python's support for procedural, functional and object oriented approaches

  • Ability to integrate with Enterprise Applications

  • Extensibility


 

I encourage you to do an internet search on "business benefits of using Python" you may find other reasons that resonate better for your situation.

Additionally, for those who are leveraging the segmenting feature for forecasting in SAP Predictive Factory, using Python could be used to accomplish the same functionality with other types of predictive models.


What type of use-cases could include predictive analytics into an application?


 

Below are some examples where an application can include predictive analytics as a differentiating feature:

  • Recommending products to customers based on prior buying patterns in on line web stores

  • Scoring customers for the customer service team based a customer’s likelihood to churn in CRM applications

  • Forecasting profit, sales growth rates in financial applications

  • Alerting maintenance teams when a bearing has an 80% chance of failing to keep operations at running 100% of the time

  • Alerting insurance agents on cases that have 90% chance of fraud.


Many SAP Partners embed SAP Predictive Analytics into their application to differentiate their own solution.  This article discusses embedding advanced analytics into applications:

https://blogs.sap.com/2016/08/29/predictive-analytics-changing-the-game-for-sap-oem-partners/

Additionally, there are perks for SAP Partners described in the article on Becoming an OEM partner has its benefits.

Prerequisites:


SAP Predictive Analytics 3.3 Desktop

 

Steps to Follow



  • First you will need to get Python. The Anaconda distribution is very popular for Python and you can download it from https://www.anaconda.com/download/ . The default Anaconda install currently installs Python version 3.6.  SAP Predictive Analytics requires Python version 3.5.  To download this version with Anaconda, download Anaconda version 4.2 which uses Python version 3.5.  Anaconda 4.2 can be found on this URL.  If you download this version, then you will not need to manage versioning with environments as the instructions below state.

  • I will continue using Anaconda3 5.0.1.  Install Anaconda using the graphical installer using the default options.




  • Open the environment settings for your computer. Press the Windows start button and type “explorer”, click on the “File Explorer” icon the appears as shown below.




  • Right click on the computer icon circled in red below and select the “Properties” option in the pop-up menu.




  • Click on the “Advanced system settings” option circled below.




  • Click on the Environment Variables button highlighted below.




 

  • Add Python environment to your Windows computer. Press the ‘New’ button boxed in red below.




  • Type ‘PYTHONPATH’ for the variable name and ‘C:\Program Files\SAP Predictive Analytics\Desktop\Automated\EXE\Clients\Python35\’ for the variable value.  Then press the OK button.




  • Again, press the ‘New’ button boxed in red below.




  • Type ‘AALIBPATH’ for the variable name and ‘C:\Program Files\SAP Predictive Analytics\Desktop\Automated\EXE\Clients\Python35\’ for the variable value.  Then press the OK button.




 

  • Select the ‘PATH’ system variable by clicking on the PATH entry in the lower dialog which is highlighted in blue (you may need to scroll down).  Click on the lower Edit button circled below.




  • Click on the New button boxed in red below. This action will add a row to the bottom of the PATH editor.




  • Enter ‘C:\Program Files\SAP Predictive Analytics\Desktop\Automated\EXE\Clients\CPP\’ for this new row and press the OK button circled below.




  • Press the OK button circle below.




  • To launch the Anaconda command line, press the Windows start button  and type “anaconda”, then click on the “Anaconda Prompt” icon the appears as shown below.




conda create -n py35 python=3.5
activate py35

 

  • The first command above installs Python version 3.5.  The second command changes the environment to use Python version 3.5.  Your command prompt should now start with (py35) c:\...  Lets run a SAP Predictive Analytics clustering sample. Type the following commands at the prompt:


cd %PYTHONPATH%\..\SAMPLES\python
python clustering.py

 

You will see the following output:



Congratulations you are ready to work Python with SAP Predictive Analytics Automated library!

  • This example uses the mathlibplot library. Add this library to your environment if you wish using the following command:


python -mpip install -U matplotlib


  • When you rerun the clustering sample again with the following command:


python clustering.py

 

You should see the following graph plotted (It may take a few seconds to render).



 

Some Python lovers prefer command line, while others like Python graphical tools.  If you are a command line person, you are ready to work with SAP Predictive Analytics and Python.  If not, your next step would be to setup a Jupyter Notebook for a more interactive experience. I have an article on this topic as well.

Related Resources


 

For more information on the Automated Analytics API, see the SAP documentation at https://help.sap.com/http.svc/download?deliverable_id=20569176

You may also want to connect with your HANA database from your Python code.  The article “Connect to SAP HANA, express edition using Python” will help you get this setup as well.  Additionally, there is a blog on connecting Python to SAP HANA on the Cloud.
2 Comments