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.
| Parameter | Description |
|---|---|
| assess | When set to True, adds predicted probabilities for event levels to the output table, which can be used by the `assess` action for model evaluation. |
| assessOneRow | When 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. |
| casOut | Specifies the output table to store the scoring results. If not specified, the results are not saved to a permanent table. |
| copyVars | Specifies 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. |
| impute | When 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. |
| includeMissing | Specifies 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. |
| listNode | Specifies 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. |
| modelId | Specifies a custom prefix for the predicted value columns in the output table. The default is `_NN_PredName_` for classification and `_NN_Pred_` for regression. |
| modelTable | Specifies the input table that contains the trained neural network model to be used for scoring. |
| table | Specifies the input data table to be scored. |
| target | Specifies 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. |
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.
| 1 | PROC 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 */ |
| 11 | QUIT; |
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`.
| 1 | PROC CAS; |
| 2 | neuralNet.annScore / |
| 3 | TABLE={name='iris_score'}, |
| 4 | modelTable={name='iris_model'}, |
| 5 | casOut={name='iris_scored', replace=true}; |
| 6 | RUN; |
| 7 | QUIT; |
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.
| 1 | PROC 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'; |
| 10 | RUN; |
| 11 | QUIT; |
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...
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...
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...