Input
- InputTable: svm_iris_input_trainThe example creates svm_iris_input_train in two steps:
- Create table svm_iris_input in sparse format by inputting table svm_iris to the Unpivoting function:
CREATE MULTISET TABLE svm_iris_input AS ( SELECT id, species, attribute, value_col FROM Unpivoting ( ON svm_iris USING TargetColumns ('Sepal_Length', 'Sepal_Width', 'Petal_Length', 'Petal_Width') Accumulate ('ID', 'Species') ) AS dt ) WITH DATA;
- From svm_iris_input, create training table svm_iris_input_train (with 80% of the rows) and testing table svm_iris_input_test (with 20% of the rows):
CREATE MULTISET TABLE svm_iris_input_train AS ( SELECT * FROM svm_iris_input WHERE id MOD 5 <> 0 ) WITH DATA; CREATE MULTISET TABLE svm_iris_input_test AS ( SELECT * FROM svm_iris_input WHERE id MOD 5 = 0 ) WITH DATA;
The testing table is input to the SVMSparsePredict_MLE function.
- Create table svm_iris_input in sparse format by inputting table svm_iris to the Unpivoting function:
The table svm_iris has four iris attributes (sepal length, sepal width, petal length, and petal width), grouped into three categories (setosa, versicolor, and virginica).
id | sepal_length | sepal_width | petal_length | petal_width | species |
---|---|---|---|---|---|
1 | 5.1 | 3.5 | 1.4 | 0.2 | setosa |
2 | 4.9 | 3 | 1.4 | 0.2 | setosa |
3 | 4.7 | 3.2 | 1.3 | 0.2 | setosa |
4 | 4.6 | 3.1 | 1.5 | 0.2 | setosa |
5 | 5 | 3.6 | 1.4 | 0.2 | setosa |
6 | 5.4 | 3.9 | 1.7 | 0.4 | setosa |
7 | 4.6 | 3.4 | 1.4 | 0.3 | setosa |
8 | 5 | 3.4 | 1.5 | 0.2 | setosa |
9 | 4.4 | 2.9 | 1.4 | 0.2 | setosa |
10 | 4.9 | 3.1 | 1.5 | 0.1 | setosa |
11 | 5.4 | 3.7 | 1.5 | 0.2 | setosa |
12 | 4.8 | 3.4 | 1.6 | 0.2 | setosa |
13 | 4.8 | 3 | 1.4 | 0.1 | setosa |
14 | 4.3 | 3 | 1.1 | 0.1 | setosa |
... | ... | ... | ... | ... | ... |
id | species | attribute | value_col |
---|---|---|---|
1 | setosa | sepal_length | 5.1 |
1 | setosa | sepal_width | 3.5 |
1 | setosa | petal_length | 1.4 |
1 | setosa | petal_width | 0.2 |
2 | setosa | sepal_length | 4.9 |
2 | setosa | sepal_width | 3.0 |
2 | setosa | petal_length | 1.4 |
2 | setosa | petal_width | 0.2 |
3 | setosa | sepal_length | 4.7 |
3 | setosa | sepal_width | 3.2 |
3 | setosa | petal_length | 1.3 |
3 | setosa | petal_width | 0.2 |
... | ... | ... | ... |
id | species | attribute | value_col |
---|---|---|---|
1 | setosa | sepal_length | 5.1 |
1 | setosa | sepal_width | 3.5 |
1 | setosa | petal_length | 1.4 |
1 | setosa | petal_width | 0.2 |
2 | setosa | sepal_length | 4.9 |
2 | setosa | sepal_width | 3.0 |
2 | setosa | petal_length | 1.4 |
2 | setosa | petal_width | 0.2 |
3 | setosa | sepal_length | 4.7 |
3 | setosa | sepal_width | 3.2 |
... | ... | ... | ... |
SQL Call
SELECT * FROM SVMSparse ( ON svm_iris_input_train AS InputTable OUT TABLE ModelTable (svm_iris_model) USING IDColumn ('id') AttributeNameColumn ('attribute') ResponseColumn ('species') AttributeValueColumn ('value1') MaxIterNum (150) Seed (0) )as dt ;
Output
message ---------------------------------------------------------------------------------------------------------------------------------------------- Model table is created successfully The model is trained with 120 samples and 4 unique attributes There are 3 different classes in the training set The model is not converged after 150 steps with epsilon 0.01, the average value of the loss function for the training set is 36.44926590032744 The corresponding training parameters are cost:1.0 bias:0.0
The model table, svm_iris_model, is in binary format.
Download a zip file of all examples and a SQL script file that creates their input tables from the attachment in the left sidebar.