clear all
// load the dataset 
use http://www.stata-press.com/data/r16/iris

// split the original dataset into training and test 
// dataset which contains 80% and 20% of observations respectively
splitsample, generate(group, replace) split(0.8 0.2) show rseed(16)

// train the model with the training dataset
// group==1 means the training dataset
pysvm iris seplen sepwid petlen petwid if group==1

// make predictions and store the prediction results 
// into a new variable irispr
pysvmpredict, predict(irispr)

// label the predicted variable
label values irispr species
label variable irispr predicted

// list the classification table for the test dataset. 
// group==2 means the test dataset
tabulate iris irispr if group==2, row