IMSTAT Procedure (Analytics)

Example 15: Training and Validating a Neural Network

Details

This IMSTAT procedure example demonstrates using the NEURAL statement to train and validate a neural network.

Program

libname example sasiola host="grid001.example.com" port=10010 tag='hps';

data example.iris; 
    set sashelp.iris;
    part=ranuni(12345); 
run;


proc imstat data=example.iris;
   where part <= .75;
   neural species / seed=12345
       input=(sepallength sepalwidth petallength petalwidth) 1
       nominal=(species)
       hidden=(2) 
       maxiter=1000 numtries=10 
       lower=-20 upper=20 
       code=(file="/data/iris_score.sas" replace)  2
       /* details */  3
       temptable;  4
   run;

   where part > .75;
   neural species / 
       lasrann=example.&_TEMPLAST_  5
       idvars=species  6
       temptable;
   run;

   table example.&_TEMPLAST_;  7
   fetch / to=5 format;
   run;
quit;

Program Description

  1. The NEURAL statement models values of the species variable based on the input variables.
  2. The CODE= option is used to save the scoring code to a file.
  3. The DETAILS option is omitted from the results but can be useful during model development because it provides details about the iterations.
  4. The TEMPTABLE option is used to save the weights from the training exercise to a temporary table.
  5. The LASRANN= option is used to reference the temporary table that has the weights from the training exercise.
  6. Specifying IDVARS= adds the target variable to the scored data set. This makes it easy to see both the actual value and the predicted value.
  7. The TABLE statement is used to access the temporary table that includes the scoring results.
To score other data with the scoring program in the /data/iris_score.sas file, you can use the SCORE statement with the CODE= option.

Output

The first display shows the results of the first NEURAL statement that is used to train the network.
Training a neural network
The second display shows the results of the second NEURAL statement that is used to validate the model. The Selected Records table shows the first five records of the scoring results table that were read with the FETCH statement.
Validate the model