neuralNet

annScore

Description

The `annScore` action scores a data table using a pre-trained artificial neural network model. This is a crucial step after training a model with `annTrain`, allowing you to apply the learned patterns to new data to make predictions. The action can generate various outputs, including predicted values, probabilities for classification tasks, and even the values of hidden layer nodes, which can be useful for feature engineering or model interpretation.

neuralNet.annScore / table={name='table-name'}, modelTable={name='model-table-name'}, casOut={name='output-table-name', replace=true};
Settings
ParameterDescription
assessWhen set to True, adds predicted probabilities for event levels to the output table, which can be used by the `assess` action for model evaluation.
assessOneRowWhen set to True, adds predicted probabilities for all event levels as separate columns (prefixed with `_NN_P_`) in the output table. This is useful for detailed assessment.
casOutSpecifies the output table to store the scoring results. If not specified, the results are not saved to a permanent table.
copyVarsSpecifies a list of variables from the input data table to be copied to the output table. This is useful for keeping identifiers or other relevant variables alongside the scoring results.
imputeWhen set to True, for observations where the target variable is not missing, its value is used as the prediction. Scoring is only performed for observations with missing target values.
includeMissingSpecifies whether to include observations with missing values for any of the model's input variables in the scoring process. By default, they are included and handled by the model's imputation logic.
listNodeSpecifies which nodes' activation values to include in the output table. 'HIDDEN' is particularly useful for dimensionality reduction through autoencoders, as it outputs the compressed feature vectors from the hidden layers.
modelIdSpecifies a custom prefix for the predicted value columns in the output table. The default is `_NN_PredName_` for classification and `_NN_Pred_` for regression.
modelTableSpecifies the input table that contains the trained neural network model to be used for scoring.
tableSpecifies the input data table to be scored.
targetSpecifies the name of the target variable in the scoring data. This is only necessary if the target variable's name in the scoring table is different from the one used during training.
Data Preparation View data prep sheet
Data Creation for Scoring

This example first creates a sample dataset `mycas.iris_score` which has the same structure as the training data but without the target variable. This simulates a real-world scenario where you want to make predictions on new, unseen data. We assume a pre-trained neural network model `mycas.iris_model` already exists, created by the `annTrain` action.

Copied!
1PROC CAS;
2 DATA mycas.iris_score;
3 SET sashelp.iris;
4 IF mod(_n_, 5) = 0 THEN DO;
5 Species = ''; /* Simulate new data without target */
6 OUTPUT;
7 END;
8 RUN;
9 
10 /* Assuming mycas.iris_model table exists from a previous annTrain action */
11QUIT;

Examples

This is a basic example of scoring the `iris_score` table using the trained model `iris_model`. The results, including the predicted species, are saved to a new table named `iris_scored`.

SAS® / CAS Code Code awaiting community validation
Copied!
1PROC CAS;
2 neuralNet.annScore /
3 TABLE={name='iris_score'},
4 modelTable={name='iris_model'},
5 casOut={name='iris_scored', replace=true};
6RUN;
7QUIT;
Result :
The action will produce an output table `mycas.iris_scored` containing the original data plus a new column `_NN_PredName_` with the predicted species for each observation.

This detailed example demonstrates how to score the `iris_score` table while also extracting the activation values of the hidden layer nodes and generating detailed assessment statistics. The `listNode='HIDDEN'` parameter saves the hidden node values, and `assessOneRow=true` creates columns for the predicted probabilities of each class. The `copyVars` parameter ensures the original `Species` and `SepalLength` columns are included in the output for comparison.

SAS® / CAS Code Code awaiting community validation
Copied!
1PROC CAS;
2 neuralNet.annScore /
3 TABLE={name='iris_score'},
4 modelTable={name='iris_model'},
5 casOut={name='iris_scored_detailed', replace=true},
6 copyVars={'Species', 'SepalLength'},
7 listNode='HIDDEN',
8 assessOneRow=true,
9 modelId='IrisPrediction';
10RUN;
11QUIT;
Result :
The output table `mycas.iris_scored_detailed` will be created. It will contain the copied variables (`Species`, `SepalLength`), the predicted species in a column named `IrisPrediction_PredName_`, the predicted probabilities for each species (e.g., `_NN_P_setosa`, `_NN_P_versicolor`, `_NN_P_virginica`), and columns for the activation values of each hidden node.

FAQ

What is the primary function of the `neuralNet.annScore` action?
What are the required input tables for the `annScore` action?
How can I include predicted probabilities for each event level in the output table?
What is the purpose of the `impute` parameter?
How can I control which nodes from the neural network are included in the scored output table?
How are missing values handled by default during scoring?

Associated Scenarios

Use Case
Customer Churn Prediction and Latent Feature Extraction for Segmentation

A telecom company wants to score new customers to predict their likelihood of churning. Additionally, they want to extract latent features from the neural network's hidden layer...

Use Case
Scoring Patient Records with Missing Data and Pre-existing Diagnoses

A healthcare provider needs to run a diagnostic prediction model on a batch of new patient records. The dataset is known to be 'dirty': some records have missing test results (i...

Use Case
High-Volume Batch Scoring of E-commerce Product Recommendations

An e-commerce platform needs to refresh product recommendations for its entire user base overnight. This involves scoring a very large table of user-product pairs against a reco...