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

The GPCLASS Procedure

Number of Training Observations Read140
Number of Training Observations Used140
Number of Testing Observations Read10
Number of Testing Observations Used10


Output 14.1.2: Descriptive Statistics

Input Variable Statistics
VariableMeanStandard
Deviation
MinMax
SepalLength57.9785718.30486443.00000079.000000
SepalWidth30.6357144.41581620.00000044.000000
PetalLength36.32857117.58901010.00000069.000000
PetalWidth11.3142867.4109441.00000025.000000


Output 14.1.3: Model Information

Model Information
Classification AlgorithmGaussian Process Classification
Inference MethodLaplacian Approximation
Random Number Seed12345
Kernel TypeLinear Kernel
Kernel Constant0
Link TypeLogit Likelihood
LA Iterations12
LA Threshold0.001
LA ConvergeYes


Output 14.1.4: Iteration Statistics

Iteration History
IterationLog 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

SpeciesSepalLengthSepalWidthPetalLengthPetalWidthlabelP_label0P_label1I_labelP_VAR_
Virginica6725581800.926530.073470151.660
Virginica6530582200.914970.085030162.480
Virginica6931542100.910790.089210116.686
Virginica7236612500.893320.106680189.129
Virginica6532512000.891930.108070109.226
Virginica6427531900.923270.076730115.094
Virginica6830552100.916750.083250124.591
Virginica5725502000.919660.080340121.267
Virginica5828512400.890700.109300167.544
Virginica6333602500.887840.112160231.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.

Last updated: September 23, 2026