GPCLASS Procedure
Getting Started: GPCLASS Procedure
Note: Input data must be in a CAS table that is accessible in your CAS session. You must refer to this table by using a two-level name. The first level must be a CAS engine libref, and the second level must be the table name. For more information, see the sections Using CAS Sessions and CAS Engine Librefs and Loading a SAS Data Set onto a CAS Server in Chapter 2, Shared Concepts.
This example uses the Toy data set to demonstrate how to use the GPCLASS procedure to perform classification, and then how to use the analytic store to save the trained model and use the saved model for future classification.
The Toy data set contains 40 observations and three variables. The variable label contains the two binary classes 1 and 0, and the other two numeric variables contain statistics about the location.
The following DATA steps load the Toy data set into your CAS session and then divide the data into the training data table, the testing data table, and another testing data table for future use with the saved model. PROC GPCLASS then uses the first 30 observations in data for training and the next 10 observations for testing. Because the ASTORE procedure is specified in this example, the trained model is saved for future prediction.
data toy;
input id x y label;
datalines;
1 0.7562437251693241 -0.4449246304395207 1
2 1.6425910060420805 -0.10293958159084055 1
3 0.5036628219528629 -0.3756019302569773 1
4 1.9356458876375808 0.1508435933753537 1
5 -0.48929352371915874 0.9004153510746639 0
6 1.9612377920931525 0.3688561398322367 1
7 -0.4457973476327784 0.923703991351446 0
8 0.897645351230446 0.13625291562699787 0
9 1.0428050419382913 0.2538945316161072 0
10 1.7841025147461618 -0.03250971343343456 1
11 0.6525149362580007 -0.5043431552576471 1
12 1.8526407982796789 0.13718466658924755 1
13 0.7736555917316961 -0.48367703386369615 1
14 -0.9816672335041904 0.33290929557635607 0
15 0.24612298119546702 -0.1868663956140018 1
16 1.99621877108224 0.3245177413955755 1
17 -0.04791750586561572 0.2659542532295433 1
18 2.110087224576905 0.5250574025280107 1
19 -0.9602167257824953 0.3787188727510752 0
20 -0.6841219033906107 0.7364079763792437 0
21 -0.9920556836181335 0.20730041712702757 0
22 2.0187106442510587 0.329144855526437 1
23 -0.9363848220016563 0.5820604427678648 0
24 0.3176242827173276 -0.23130675115061858 1
25 -0.08766070923125874 0.9228708936342618 0
26 0.9503505174789424 0.22930242945171128 0
27 1.9137065930212924 0.04727138786088236 1
28 -0.5740857513898902 0.7860024177122371 0
29 1.7311039665579235 -0.15822368653296057 1
30 0.15601420930527587 -0.012971094201072592 1
31 0.03440178911461349 0.35665294277687765 1
32 1.734352820043718 -0.16711805469096147 1
33 0.9743086385469273 -0.03306556437399488 0
34 1.3646032525150116 -0.33201208895864687 1
35 -1.000588826462477 0.057717691210846855 0
36 0.0937572740953208 -0.0973344952572724 1
37 -0.2791878004436257 0.9850672774312587 0
38 -0.9994507007532529 0.33048792628967455 0
39 0.9990673318735382 -0.505133345971595 1
40 0.8997014125100633 0.5246863891252541 0
;
data mylib.toy_train;
set toy (obs=30);
run;
data mylib.toy_test;
set toy(firstobs=31 obs=35);
run;
data mylib.toy_test1;
set toy(firstobs=36);
run;
These statements assume that your libref is named mylib, but you can substitute any appropriately named libref.
The following statements use PROC GPCLASS to perform classification on the training data:
proc gpclass
data=mylib.toy_train
testdata=mylib.toy_test
seed=12345
nThreads=32
link=Logit;
input x y;
target label/level=nominal;
kernel gaussian(sigma=1);
inference LA(maxIter=1000 threshold=0.001);
savestate rstore=mylib.astore;
output out=mylib.score copyvars=(x y label);
display nObs descStats modelInfo iterStats;
run;
This PROC GPCLASS generates four ODS tables, which are shown in Figure 1 through Figure 4.
Figure 1: Number of Observations
| Number of Training Observations Read | 30 |
|---|---|
| Number of Training Observations Used | 30 |
| Number of Testing Observations Read | 5 |
| Number of Testing Observations Used | 5 |
Figure 2: Descriptive Statistics
| Input Variable Statistics | ||||
|---|---|---|---|---|
| Variable | Mean | Standard Deviation | Min | Max |
| x | 0.634783 | 1.079817 | -0.992056 | 2.110087 |
| y | 0.200177 | 0.412637 | -0.504343 | 0.923704 |
Figure 3: Model Information
| Model Information | |
|---|---|
| Classification Algorithm | Gaussian Process Classification |
| Inference Method | Laplacian Approximation |
| Random Number Seed | 12345 |
| Kernel Type | Gaussian Kernel |
| Kernel Sigma | 1 |
| Link Type | Logit Likelihood |
| LA Iterations | 4 |
| LA Threshold | 0.001 |
| LA Converge | Yes |
Figure 4: Iteration Statistics
| Iteration History | |
|---|---|
| Iteration | Log Likelihood |
| 1 | -16.197960 |
| 2 | -15.870310 |
| 3 | -15.828555 |
| 4 | -15.827863 |
In this example, PROC GPCLASS generates the classification score table mylib.score, which contains the predicted class labels and probabilities. The following statements print the table shown in Figure 5:
proc print noobs data=mylib.score;
run;
Figure 5: Classification Score Table
| x | y | label | P_label0 | P_label1 | I_label | P_VAR_ |
|---|---|---|---|---|---|---|
| 0.03440 | 0.35665 | 1 | 0.57263 | 0.42737 | 0 | 0.37342 |
| 1.73435 | -0.16712 | 1 | 0.21402 | 0.78598 | 1 | 0.38873 |
| 0.97431 | -0.03307 | 0 | 0.29224 | 0.70776 | 1 | 0.33329 |
| 1.36460 | -0.33201 | 1 | 0.22919 | 0.77081 | 1 | 0.40313 |
| -1.00059 | 0.05772 | 0 | 0.67936 | 0.32064 | 0 | 0.52435 |
PROC GPCLASS also generates the analytic store table by using the SAVESTATE statement. This table saves the trained model and uses it for testing, as shown in the following code:
proc astore;
score data=mylib.toy_test1 out=mylib.gpcnewscore
rstore=mylib.astore;
run;
The following statements print the prediction for the testing data in the CAS table mylib.gpcnewscore, which is shown in Figure 6:
proc print noobs data=mylib.gpcnewscore;
run;
Figure 6: Classification Scores for Testing Data
| P_label0 | P_label1 | I_label | P_VAR_ |
|---|---|---|---|
| 0.41729 | 0.58271 | 1 | 0.37123 |
| 0.73734 | 0.26266 | 0 | 0.46789 |
| 0.73010 | 0.26990 | 0 | 0.45856 |
| 0.24254 | 0.75746 | 1 | 0.42171 |
| 0.43640 | 0.56360 | 1 | 0.46223 |