GPCLASS Procedure
Example 14.1 Performing Classification on Iris Data
Note: Input data must be in a table that is accessible in your session. You can refer to this table by using a two-level name. The first level is a libref, and the second level is the table name. For more information, see the section Using SAS Viya Workbench in Chapter 2, Shared Concepts.
This example uses the Iris data table to demonstrate how to use the GPCLASS procedure to perform classification. There are three clusters in the Iris data. First, the observations are separated into two classes: rows of the species Setosa are labeled as class 1, and rows of the species Versicolour and Virginica are labeled as class 0. Then the data are split into subsets for training and testing. The following DATA steps generate the Iris data:
data iris;
set sashelp.iris;
run;
data iris_binary_class;
set iris;
if Species = 'Setosa' then label=1;
else label=0;
run;
data mylib.iris_train;
set iris_binary_class(obs=140);
run;
data mylib.iris_test;
set iris_binary_class(firstobs=141 obs=150);
run;
These statements assume that your libref is named mylib, but you can substitute any appropriately defined libref.
The following statements run PROC GPCLASS and output the results to data tables and ODS tables. In this example, a linear kernel is used to separate the two classes.
proc gpclass
data=mylib.iris_train
testdata=mylib.iris_test
seed=12345
nThreads=32
link=Logit;
input SepalLength SepalWidth PetalLength PetalWidth;
target label/level=nominal;
kernel linear(constant=0);
inference LA(maxIter=100 threshold=0.001);
output out=mylib.iris_score copyvars=(_all_);
display nObs descStats modelInfo iterStats;
run;
PROC GPCLASS generates four ODS tables, which are shown in Output 14.1.1 through Output 14.1.4.
Output 14.1.1: Number of Observations
| Number of Training Observations Read | 140 |
|---|---|
| Number of Training Observations Used | 140 |
| Number of Testing Observations Read | 10 |
| Number of Testing Observations Used | 10 |
Output 14.1.2: Descriptive Statistics
| Input Variable Statistics | ||||
|---|---|---|---|---|
| Variable | Mean | Standard Deviation | Min | Max |
| SepalLength | 57.978571 | 8.304864 | 43.000000 | 79.000000 |
| SepalWidth | 30.635714 | 4.415816 | 20.000000 | 44.000000 |
| PetalLength | 36.328571 | 17.589010 | 10.000000 | 69.000000 |
| PetalWidth | 11.314286 | 7.410944 | 1.000000 | 25.000000 |
Output 14.1.3: Model Information
| Model Information | |
|---|---|
| Classification Algorithm | Gaussian Process Classification |
| Inference Method | Laplacian Approximation |
| Random Number Seed | 12345 |
| Kernel Type | Linear Kernel |
| Kernel Constant | 0 |
| Link Type | Logit Likelihood |
| LA Iterations | 12 |
| LA Threshold | 0.001 |
| LA Converge | Yes |
Output 14.1.4: Iteration Statistics
| Iteration History | |
|---|---|
| Iteration | Log Likelihood |
| 1 | -39.057368 |
| 2 | -23.031626 |
| 3 | -15.809021 |
| 4 | -11.866309 |
| 5 | -9.316223 |
| 6 | -7.455245 |
| 7 | -6.042881 |
| 8 | -5.046018 |
| 9 | -4.481966 |
| 10 | -4.290494 |
| 11 | -4.265787 |
| 12 | -4.265268 |
In this example, PROC GPCLASS generates the classification score table mylib.iris_score, which lists the predicted class labels and probabilities. The following statements print the table shown in Output 14.1.5:
proc print noobs data=mylib.iris_score;
run;
Output 14.1.5: Classification Score Table
| Species | SepalLength | SepalWidth | PetalLength | PetalWidth | label | P_label0 | P_label1 | I_label | P_VAR_ |
|---|---|---|---|---|---|---|---|---|---|
| Virginica | 67 | 25 | 58 | 18 | 0 | 0.92653 | 0.07347 | 0 | 151.660 |
| Virginica | 65 | 30 | 58 | 22 | 0 | 0.91497 | 0.08503 | 0 | 162.480 |
| Virginica | 69 | 31 | 54 | 21 | 0 | 0.91079 | 0.08921 | 0 | 116.686 |
| Virginica | 72 | 36 | 61 | 25 | 0 | 0.89332 | 0.10668 | 0 | 189.129 |
| Virginica | 65 | 32 | 51 | 20 | 0 | 0.89193 | 0.10807 | 0 | 109.226 |
| Virginica | 64 | 27 | 53 | 19 | 0 | 0.92327 | 0.07673 | 0 | 115.094 |
| Virginica | 68 | 30 | 55 | 21 | 0 | 0.91675 | 0.08325 | 0 | 124.591 |
| Virginica | 57 | 25 | 50 | 20 | 0 | 0.91966 | 0.08034 | 0 | 121.267 |
| Virginica | 58 | 28 | 51 | 24 | 0 | 0.89070 | 0.10930 | 0 | 167.544 |
| Virginica | 63 | 33 | 60 | 25 | 0 | 0.88784 | 0.11216 | 0 | 231.991 |
From the score table, you can see that by using a simple linear kernel, PROC GPCLASS produces a perfect prediction of good confidence, with the predicted probabilities close to 1.