16.20 - NaiveBayesPredict Example - Teradata Database - Teradata Vantage NewSQL Engine

Teradata Vantage™ - NewSQL Engine Analytic Functions

Product
Teradata Database
Teradata Vantage NewSQL Engine
Release Number
16.20
Release Date
July 2019
Content Type
Programming Reference
Publication ID
B035-1206-162K
Language
English (United States)

Input

  • Input table: nb_iris_input_test
  • Model: nb_iris_model

The model is created in the Naive Bayes example in Teradata Vantage™ Machine Learning Engine Analytic Function Reference, B700-4003.

Input Table Column Descriptions
Column Description
id Unique identifier of observation
sepal_length Numeric
sepal_width Numeric
petal_length Numeric
petal_width Numeric
species Setosa, versicolor, or virginica
nb_iris_input_test
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
nb_iris_model
class variable type category cnt sum sumSq totalcnt
setosa sepal_width NUMERIC   40 136.700000524521 473.290003499985 40
setosa petal_width NUMERIC   40 10.1000002026558 3.03000012755394 40
setosa sepal_length NUMERIC   40 199.900000095367 1004.27000005722 40
setosa petal_length NUMERIC   40 57.6999998092651 84.2099996709824 40
versicolor sepal_width NUMERIC   40 111.10000038147 313.130002088547 40
versicolor petal_width NUMERIC   40 53.299999833107 72.7099995040894 40
versicolor sepal_length NUMERIC   40 239.599999427795 1446.13999296188 40
versicolor petal_length NUMERIC   40 172.399999141693 752.219992570878 40
virginica sepal_width NUMERIC   40 118.799999952316 356.539999780655 40
virginica petal_width NUMERIC   40 81.1999989748001 166.999995970726 40
virginica sepal_length NUMERIC   40 264.400000572205 1764.92000530243 40
virginica petal_length NUMERIC   40 222.299999713898 1249.1499958992 40

SQL Call

DROP TABLE nb_iris_predict;

CREATE MULTISET TABLE nb_iris_predict AS (
  SELECT * FROM NaiveBayesPredict (
    ON nb_iris_input_test PARTITION BY ANY
    ON nb_iris_model AS Model DIMENSION
    USING
    IDColumn ('id')
    NumericInputs ('sepal_length','sepal_width','petal_length','petal_width')
    Responses ('virginica','setosa','versicolor')
  ) AS dt
) WITH DATA;

Output

This query returns the following table:

SELECT * FROM nb_iris_predict ORDER BY 1;

The output provides a prediction for each row in the test data set and specifies the log likelihood values that were used to make the predictions for each category.

id prediction loglik_virginica loglik_setosa loglik_versicolor
5 setosa -60.9907330174083 0.940424559067427 -38.2319825308929
10 setosa -61.5861966261907 -0.173043897170957 -37.6660830556247
15 setosa -64.7169548001753 -3.55476375390931 -42.613272284101
20 setosa -57.7992844148636 0.531796840642284 -35.7613053354934
25 setosa -55.0939143017897 -3.23703029869347 -32.1179858509341
30 setosa -58.0673073752287 0.109611164911179 -34.9285997859276
35 setosa -58.1980267787658 0.660202577013632 -34.9335988704833
40 setosa -58.3538858459019 0.976840811041703 -35.4425587940391
45 setosa -50.3847602463201 -4.36921429673761 -29.0537478266948
50 setosa -59.4745348026195 1.00257959230347 -36.5026022674224
55 versicolor -5.22108005914589 -270.465431908161 -1.7396367893394
60 versicolor -11.3356467465064 -174.565470791378 -2.31925264962004
65 versicolor -12.6496488706934 -138.435722453706 -2.1898005756116
70 versicolor -15.236843619572 -152.47255627778 -2.3538459106499
75 versicolor -8.34632493685681 -214.383653794905 -1.14727508911532
80 versicolor -18.455946984498 -109.900955754698 -3.72743011721095
85 versicolor -7.00283150694931 -249.656488976769 -2.00455589365379
90 versicolor -12.0279925543069 -177.470336291088 -1.74539749109463
95 versicolor -10.1802450220293 -198.037109900803 -1.10567314638237
100 versicolor -10.1315405651018 -187.294956922171 -1.02885306444447
105 virginica -1.58321671192447 -540.56351949849 -14.859643718252
110 virginica -6.11301966870239 -654.801984259278 -28.8385135092999
115 virginica -3.64635253153959 -456.647579953406 -15.3298808321577
120 versicolor -7.73615017754911 -322.909009762056 -3.53629430321742
125 virginica -1.87627054598219 -509.817023097936 -13.7515396871732
130 virginica -3.36908052149115 -469.802937074554 -9.13832860900173
135 versicolor -5.81482980902253 -403.678170868448 -4.51644862072851
140 virginica -1.48430911768034 -463.610989255182 -12.0238603485835
145 virginica -3.82266629516761 -576.395460020916 -22.6942168473031
150 virginica -2.57004648415525 -366.506113945482 -4.84887216455807