The SPARSEML Procedure

Example 21.1 Sparse Data Set Example

This example uses the SPARSEML procedure to train a model by using the same data set, smldata, as in the section Getting Started: SPARSEML Procedure. Here, you can add a column id to the smldata data set to serve as the ID variable, as shown in the following statements:

data smldata;
    id = _N_;
    set smldata;
run;

You can load the smldata data set into your CAS session by specifying your CAS engine libref in the second statement in the following DATA step:

data mycas.smldata;
    set smldata;
run;

These statements assume that the CAS engine libref is named mycas, but you can substitute any appropriately named CAS engine libref.

The following statements use PROC SPARSEML to run the sparse machine learning algorithm on the mycas.smldata data table and generate the analytic store mycas.mystate:

proc sparseml data= mycas.smldata
    TOLERANCE=0.01
    C = 5.5
    MAXITERS=10
    ;
    input vars;
    savestate rstore=mycas.mystate;
    output out=mycas.trainingout copyvars=(id);
run;

The PROC SPARSEML statement has options such as TOLERANCE=, C=, and MAXITERS=. The INPUT statement defines the input variable vars, which includes both target and sparse input values. The SAVESTATE statement specifies the remote data table mycas.mystate, where the analytic store is saved. The OUTPUT statement shows that the training output table is mycas.trainingout, which includes the variable id.

PROC SPARSEML generates several ODS tables, some of which are shown in Output 21.1.1 through Output 21.1.3.

The "Data Information" table in Output 21.1.1 shows that the number of observations is 15, the number of features is 2, and the number of sparse elements is 26.

Output 21.1.1: Sparse Data Information

The SPARSEML Procedure

Data Information
Number of Rows15
Number of Features2
Number of Sparse Elements26


The "Misclassification Matrix" table in Output 21.1.2 shows that among the total of fifteen observations, nine observations are classified as 1, and six observations are classified as –1. The number of correctly predicted 1 observations is four, and the number of correctly predicted –1 observations is six. Thus the accuracy is 66.67%, as indicated in the "Fit Statistics" table in Output 21.1.3.

Output 21.1.2: Misclassification Matrix

Misclassification Matrix
ObservedTraining Prediction
1-1Total
1459
-1066
Total41115


Output 21.1.3: Fit Statistics

Fit Statistics
StatisticTraining
Accuracy0.6667
Error0.3333
Sensitivity0.4444
Specificity1.0000


The generated analytic store mycas.mystate can be used by PROC ASTORE to score data. For example, you can score the mycas.smldata data table as follows:

proc astore;
    score data=mycas.smldata
       out=mycas.smlscore
       rstore=mycas.mystate
       copyvars=(id)
       ;
    run;
quit;

The score output data are saved in the mycas.smlscore data table.

Last updated: November 11, 2020