SAP Thought Leadership Paper Analytics Solutions from SAP SAP Predictive Analytics Embed Deep-Learning Techniques into Predictive Modeling Using SAP Predictive Analytics for Complex Modeling
Table of Contents 4 Neural Networks 5 Deep-Learning Custom R Component 9 Training the Deep-Learning Algorithm 12 Scoring Using a Trained Deep-Learning Model About the Author Paul Pallath, PhD, Chief Data Scientist and Director, SAP Advanced Analytics, Dublin 2 / 16
In the past decades, computer science has completely changed human life in almost every domain. A fantastic dream to create artificial intelligence has culminated in computers that interact with human beings and even carry out their own thought processes. Modeled on artificial neural networks (ANNs) inspired by biological neural networks, ANNs have been successfully applied to a staggering range of applications. 3 / 16
Neural Networks Biological neural networks make up the central nervous system of animals and are generally centered in the brain. In machine learning, ANNs are made up of statistical learning algorithms that emulate biological neural networks. ANNs are even presented as systems of interconnected neurons that compute values from input. ANNs can estimate or approximate functions that depend on a large quantity and variety of unknown input. Thanks to their adaptive nature, ANNs are capable of machine learning and pattern recognition. However, despite their popularity and the variety of applications to which they have been applied, neural network models are known as shallow architectures, which comprise two or three layers of computation, similar to many other machine learning methods. In recent years, deep-structured learning also known as deep learning, hierarchical learning, and deep architectures has reportedly performed more efficiently than shallow architectures, especially when the problem to be solved is characterized by complex behaviors and highly varying mathematical functions. Deep-learning networks, which derive their impetus from circuit complexity theory as well as from biological models, usually have multiple hidden layers. The hidden layer is where the network stores its internal abstract representation of the training data. In deep learning, the hidden layers are computed in an entirely different fashion than in traditional neural networks. In deep networks, each layer is pretrained with an unsupervised learning algorithm; it learns to perform a nonlinear transformation of its input (the output of the previous layer), which captures more highly abstracted features from that input. In the final training phase, the deep architecture is fine-tuned according to a supervised training criterion for a gradient-based optimization. In short, deep learning is made up of sets of algorithms that learn by progressing through multiple levels of abstraction to model complex relationships among data. For an overview and concise discussion of deep learning, please refer to the thought leadership paper, An Introduction to Deep Learning: Examining the Advantages of Hierarchical Learning. The following sections discuss a very easy way to bring deep-learning algorithms into SAP Predictive Analytics software and use them for modeling. SAP PREDICTIVE ANALYTICS AND DEEP LEARNING Using the Expert Analytics option of the SAP Predictive Analytics software, a data scientist can create custom R code and add it to the product as one or more components. The R components can then be used together with the solution s other components to perform complex modeling processes, such as predictive modeling. The R library provides a rich collection of data-mining algorithms and two deep-learning toolkits: deepnet (http://cran.r-project.org/web/packages/deepnet /index.html) and darch (http://cran.r-project.org /web/packages/darch/index.html). The toolkits contain algorithms that can be used to build models for deep learning. 4 / 16
Deep-Learning Custom R Component Once the Expert Analytics option is chosen, the R Component option is offered (see Figure 1) for expert users to build custom R components. They have access to the deepnet library in R to create the deep-learning custom R component, and they will be able to work online or offline. Once the deep-learning custom R component is created, it is trained to build a classification model that distinguishes between gamma signals from background signals for the MAGIC Gamma Telescope Data Set by R.K. Bock (https://archive.ics.uci.edu /ml/datasets MAGIC+Gamma+Telescope). When the user chooses the R Component option as shown in Figure 1, a wizard to edit a custom R component is presented, prompting the user to name the component being created (see Figure 2). The component then appears with that name in the algorithm section of the product. Figure 1: The R Component with the Experts Analytics Option Launched Figure 2: Naming the Custom-R Component 5 / 16
After clicking Next, the user will be able to copy and paste the R function into the Script Editor text box or load the R script using the Load R Script option (see Figure 3). The code written in R has to be written in function format. The component will have algorithm-specific parameters like frame, independent columns, and target column which the user may want to adjust during modeling. Figure 3: Parameters for Custom-R Component Deep-structured learning also known as deep architectures has reportedly outperformed shallow architectures, especially when the problem to be solved is characterized by complex behaviors and highly varying mathematical functions. 6 / 16
The R code snippet for the deep-learning component is shown in Figure 4. It has two functions: DNN, used to train the model, and DNNFunctionmodel, used to score the trained model on new unseen or unlabeled data. Figure 4: R Code for the Deep-Learning Custom Component 7 / 16
When users drop the R function onto the designer canvas for complex modeling (see Figure 5), they can use the wizard to expose all the parameters to the R function as configurable parameters of the custom components. On clicking Finish, the deep-learning custom component will be included under the algorithm sections. Figure 5: Using the Wizard to Expose Parameters 8 / 16
Training the Deep-Learning Algorithm Users can now drag the deep-learning custom component onto the canvas and embed it as part of a complex workflow in combination with other preprocessing and data manipulation algorithms. In Figure 6, the deep-learning custom R component is now connected to the data source. Figure 6: Connecting the Custom R Component to the Data Source Deep-learning networks derive their impetus from circuit complexity theory as well as from biological models. They usually have multiple hidden layers, where the network stores its internal abstract representation of the training data. 9 / 16
On double-clicking the deep-learning component, the parameter window is displayed, allowing the user to configure parameters that were defined when the custom component was created (see Figure 7). Figure 7: Parameter Window 10 / 16
Once the parameters are configured, the deeplearning algorithm can be trained on the input data. A message box will show execution status (see Figure 8). On successful execution of the deep-learning algorithm training, the custom component creates a visualization that summarizes performance and an ROC curve for the trained model as a custom chart (see Figure 9). Figure 8: Execution Status Message Box Figure 9: Visualization of Algorithm Training Performance 11 / 16
Scoring Using a Trained Deep-Learning Model Once the deep-learning algorithm has been trained, it can be saved as a model and used later to score unseen data. The option for saving the algorithm as a model is activated from the dialog box that appears when the user clicks the deeplearning component (see Figure 10). After saving the trained algorithm as a model, the model appears in the right-hand panel under the Model section (see Figure 11). Figure 10: Saving the Trained Algorithm As a Model Figure 11: The Saved Model 12 / 16
In order to use the model to score unseen data in different analyses, the user must first export the model as a spar file (a proprietary file format for expert analytics). The user can then import it to use it in a new analysis. When the user clicks the model to be exported, the Component Action option appears. The user is prompted to specify a name for the spar file and the destination to which the model is to be exported (see Figure 12). To use the model for scoring in a new analysis, click on the Import Model option as shown in Figure 13. Figure 12: Exporting a Model As a Spar File Figure 13: Importing a Model into a New Analysis 13 / 16
The user will be prompted to navigate to the folder containing the spar file. An option facilitates the user s selection of trained models to be imported into the analysis (see Figure 14). The user can select more than one model to import into the analysis. In Figure 15, the trained deeplearning model has been chosen to be imported into the new analysis. Figure 14: Navigating to the Folder Containing the Spar File Figure 15: Selecting Models to Be Imported 14 / 16
Once the model has been successfully imported, it will be visible under the Models section as highlighted in Figure 16. The imported model can now be used to score new data sets. It does this by building a scoring chain and executing the chain to get the scores. A message appears indicating execution status (see Figure 17). On successful execution of the scoring chain, the scores for the unseen data are shown in the results tab. Figure 16: Successfully Imported Model Figure 17: Execution Status of Analysis Results 15 / 16
SUMMARY SAP Predictive Analytics provides an excellent feature in its expert mode to embed custom R code as one more component within the solution. Once the custom component is created, it is available to the user for recurrent modeling. We have shown how complex algorithms like a deep-learning custom component can be readily embedded into the SAP Predictive Analytics software, making the state-of-the-art algorithm available for all users of SAP Predictive Analytics, which they can then use in conjunction with the solution s other features. SAP Predictive Analytics provides a feature in its expert mode to embed custom R code as one more component within the solution. Once the custom component is created, it is available to the user for recurrent modeling. 16 / 16 Studio SAP 38083enUS
No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP SE or an SAP affiliate company. SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP SE (or an SAP affiliate company) in Germany and other countries. Please see http://www.sap.com/corporate-en/legal/copyright/index.epx#trademark for additional trademark information and notices. Some software products marketed by SAP SE and its distributors contain proprietary software components of other software vendors. National product specifications may vary. These materials are provided by SAP SE or an SAP affiliate company for informational purposes only, without representation or warranty of any kind, and SAP SE or its affiliated companies shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP SE or SAP affiliate company products and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty. In particular, SAP SE or its affiliated companies have no obligation to pursue any course of business outlined in this document or any related presentation, or to develop or release any functionality mentioned therein. This document, or any related presentation, and SAP SE s or its affiliated companies strategy and possible future developments, products, and/or platform directions and functionality are all subject to change and may be changed by SAP SE or its affiliated companies at any time for any reason without notice. The information in this document is not a commitment, promise, or legal obligation to deliver any material, code, or functionality. All forward-looking statements are subject to various risks and uncertainties that could cause actual results to differ materially from expectations. Readers are cautioned not to place undue reliance on these forward-looking statements, which speak only as of their dates, and they should not be relied upon in making purchasing decisions.