-
Notifications
You must be signed in to change notification settings - Fork 10
Scoring in the Cas Server
One of the repeating pattern I see in many of the POCs is embedding scoring in user's web application. This blog shows how you can develop such applications with minimal code. The four use cases are:
- Model is published to MAS
- Model is published to a CAS destination
- Model code is datastep code stored in a modelTable(sashdat)
- Model code is in an astore stored in a sashdat.
_The MAS use case is discussed in another section.
The flow for scoring is shown in the diagram below. This flow applies for the use cases 2 thru 4.
Please see the section on Setup later in this document on how to import restaf and restaflib into your application
A typical code for scoring using models published to cas destination is shown below. Besides the usual restaf calls to logon to the server, the two key methods are:
- casSetup - This is used to obtain a cas session. The only parameter is the store
- caslScore - This method executes the scoring on cas and returns the score information. The three arguments to this method are:
- store - the restaf store object
- session - the cas session object obtained via casSetup
- payload - Information to be used for scoring. See the description below
The payload(see example below) has the following data:
-
The name of the model - this is used only in the case of model published to a cas destination
-
The caslib and name of where the model is stored(a sashdat)
-
The scenario to be scored
let store = restaf.initStore(); /* (1) */ store.logon(payload) .then ( () => example()) .catch(err) => console.log(e)
async function example() {
let {session} = await restaflib.casSetup(store); /* (2) */ let scenario = { /* (3) */ modelName: 'Gradient\_Boosting\_7adb0404\_85e3\_474d\_9d03\_1059ef7ae008', model : { caslib: 'public', name: 'testpublish' }, scenario : { sensor\_ratio : 4.3, days\_out\_of\_service: 5 } }; let r = await restaflib.caslScore(store, session, scenario); /* (4) */ console.log(JSON.stringify(r, null,4));
}
The result is a Javascript object with the data returned from scoring. In the example above the result is:
{
"days_out_of_service": 5,
"sensor_ratio": 4.3,
"_Index_": 1,
"EM_EVENTPROBABILITY": 0.10521221221641,
"I_FAILURE": " 0",
"P_FAILURE0": 0.89478778778358,
"P_FAILURE1": 0.10521221221641,
"_WARN_": "",
"EM_CLASSIFICATION": " 0",
"EM_PROBABILITY": 0.89478778778358
}
The code is identical to the one show above. The modelName is ignored in these cases. The model refers to the sashdat where the datastep code or the astore is saved. See this link for examples of all 3 use cases.
- caslScore method will load the model if it is not in memory
- If there are multiple models whose name only vary in case, the first one found will be used
- The casl code used for scoring can be found here
Include the following two script tags.
<script src="https://unpkg.com/@sassoftware/restaf/dist/restaf.min.js"></script>
<script src="https://unpkg.com/@sassoftware/restaflib/dist/restaflib.min.js"></script>
Two globals restaf and restaflib will be available for use in your script tags.
Install restaf and restaflib using the following command
npm install @sassoftware/restaf @sassoftware/restaflib
.... Under construction...
-
restaf
-
restaflib
-
Examples:
- Cas Server
- Compute Server
- Scoring with MAS
- Scoring with CAS
- Utility
-
CAS Related Functions
-
MAS Related Functions
-
Compute Server Related Functions
-
Reports Related Functions
-
Interactive CLI
-
Special Topic