The analytical lifecycle has many steps and every single one is very important if you want to develop a predictive model that can automatically make intelligent decisions as part of your business processes. Arguably, the step of executing your model in a decision process and making decisions based on the model’s prediction in an automated way is the most important step. That is because during this step, the often-significant investment in the development of the model is returned and a model that is not deployed will not create business benefit.
While in many cases the application of predictive models, especially artificial intelligence models, is targeted at real-time applications, today many use cases depend on the execution of predictive models in batch. Organizations apply predictive models to large databases for customer journey applications, such as credit application scoring, next best actions, churn predictions and others.
For these batch applications it is as important to quickly and easily migrate a model from the development to the production environment. In this blog, I would like to showcase how easy it is to score a predictive model in batch that was developed in SAS Model Studio, which is part of SAS Visual Data Mining and Machine Learning (SAS VDMML). From the very first design ideas of SAS VDMML, the integration of model development and model execution has always been a very important product development aspect.
So, let’s assume you have developed your favorite predictive model in VDMML using SAS Model Studio. Using the pipeline comparison facility, you decided which model won your model tournament and will be used to batch score new data. The video, How to compare models in SAS steps through this process. The figure below shows the selected champion model in the pipeline comparison tab of SAS Model Studio.
You now have 3 options to score your favorite model in the SAS Viya environment:
Let’s describe the different options quickly. For this showcase we will use a model that provides scoring assets in a so-called analytical store or Astore. An Astore is a binary file that contains the state from a predictive analytic procedure. This state from a predictive analytic procedure, such as a random forest or gradient boosting, is created using the results from the training phase of model development. Astores can be created from predictive models developed in SAS VDMML or in SAS Enterprise Miner.
In the SAS Model Studio interface, download the Astore batch scoring code by clicking on the overflow menu in the Pipeline Comparison tab (see figure below).
The downloaded ZIP file will provide you with a program called dmcas_epscorecode.sas. This program is a DS2 program that will call the Astore to score new data. The download action also copies the model’s Astore file into the CAS Model library.
In the SAS Viya developer’s environment, SAS Studio, you can now open the program dmcas_epscorecode.sas. You will have to provide a few parameters to the program to adapt it to your selected execution environment, such as the name and the port number of your CAS server.
Then you load the Astore file into memory and use the provided program - dmcas_epscorecode.sas - to apply it to new data as shown in the figure below.
The result will be a CAS table that contains the scores for every record.
Another method to score Astore models in batch is to use the publishing facility in SAS Model Studio. In the Pipeline Comparison tab, select Publish Model from the overflow menu as shown in the figure below.
In the publishing wizard, select the publishing destination CAS for batch scoring and provide a name for the published model. The publishing creates an entry of the model in the destination table; by default, that table is called SAS_MODEL_TABLE. Publishing destinations are usually defined by your SAS Administrator in SAS Environment Manager. For more details. Please refer to the online documentation.
And finally, we can use an API that is created automatically for batch scoring and can be called from different front ends, such as SAS, Python or REST. In the Pipeline Comparison tab of SAS Model Studio, select Download score API from the overflow menu. Then choose SAS as the front end.
Upload the provided SAS program to SAS Studio and insert the required parameters to run the program.
Running this code will trigger the execution of the scoring in SAS Viya and creates the scoring output table in the CAS environment.
The examples in this blog hopefully demonstrated how easy it is to score Astore models in CAS using different batch scoring interfaces.
In a following blog, I will describe how to score Astore models created in SAS Model Studio from a Jupyter notebook using Python.
Finally, I would like to thank my colleagues at SAS who helped reviewing and publishing this blog.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.