This code divides the 150 data rows into a training data set (80%) and a testing data set (20%):
DROP TABLE IF EXISTS nb_iris_input_train; DROP TABLE IF EXISTS nb_iris_input_test; CREATE TABLE nb_iris_input_train AS SELECT * FROM nb_input_iris WHERE id%5!=0; CREATE TABLE nb_iris_input_test AS SELECT * FROM nb_input_iris WHERE id%5=0; SELECT * FROM nb_iris_input_train ORDER BY id;
Alternatively, you can do the preceding task with the Sample or RandomSample function.
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 |
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 |
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 |
16 | 5.7 | 4.4 | 1.5 | 0.4 | setosa |
... | ... | ... | ... | ... | ... |
SELECT * FROM nb_iris_input_test ORDER BY id;
id | sepal_length | sepal_width | petal_length | petal_width | species |
---|---|---|---|---|---|
5 | 5 | 3.6 | 1.4 | 0.2 | setosa |
10 | 4.9 | 3.1 | 1.5 | 0.1 | setosa |
15 | 5.8 | 4 | 1.2 | 0.2 | setosa |
20 | 5.1 | 3.8 | 1.5 | 0.3 | setosa |
25 | 4.8 | 3.4 | 1.9 | 0.2 | setosa |
30 | 4.7 | 3.2 | 1.6 | 0.2 | setosa |
35 | 4.9 | 3.1 | 1.5 | 0.2 | setosa |
40 | 5.1 | 3.4 | 1.5 | 0.2 | setosa |
45 | 5.1 | 3.8 | 1.9 | 0.4 | setosa |
50 | 5 | 3.3 | 1.4 | 0.2 | setosa |
55 | 6.5 | 2.8 | 4.6 | 1.5 | versicolor |
60 | 5.2 | 2.7 | 3.9 | 1.4 | versicolor |
65 | 5.6 | 2.9 | 3.6 | 1.3 | versicolor |
70 | 5.6 | 2.5 | 3.9 | 1.1 | versicolor |
75 | 6.4 | 2.9 | 4.3 | 1.3 | versicolor |
80 | 5.7 | 2.6 | 3.5 | 1 | versicolor |
85 | 5.4 | 3 | 4.5 | 1.5 | versicolor |
90 | 5.5 | 2.5 | 4 | 1.3 | versicolor |
95 | 5.6 | 2.7 | 4.2 | 1.3 | versicolor |
100 | 5.7 | 2.8 | 4.1 | 1.3 | versicolor |
105 | 6.5 | 3 | 5.8 | 2.2 | virginica |
110 | 7.2 | 3.6 | 6.1 | 2.5 | virginica |
115 | 5.8 | 2.8 | 5.1 | 2.4 | virginica |
120 | 6 | 2.2 | 5 | 1.5 | virginica |
125 | 6.7 | 3.3 | 5.7 | 2.1 | virginica |
130 | 7.2 | 3 | 5.8 | 1.6 | virginica |
135 | 6.1 | 2.6 | 5.6 | 1.4 | virginica |
140 | 6.9 | 3.1 | 5.4 | 2.1 | virginica |
145 | 6.7 | 3.3 | 5.7 | 2.5 | virginica |
150 | 5.9 | 3 | 5.1 | 1.8 | virginica |