1.1 - 8.10 - KNN Example - Teradata Vantage

Teradata Vantage™ - Machine Learning Engine Analytic Function Reference

Product
Teradata Vantage
Release Number
1.1
8.10
Release Date
October 2019
Content Type
Programming Reference
Publication ID
B700-4003-079K
Language
English (United States)

Input

The TrainingData table has as dimensions five attributes of personal computers—price, speed, hard disk size, RAM, and screen size. The table has 5008 rows, categorized into eight price categories.

TrainingTable: computers_train1_clustered
id price speed hd ram screen computer_category
1 1499 25 80 4 14 SPECIAL
2 1795 33 85 2 14 SUPER
3 1595 25 170 4 15 SPECIAL
4 1849 25 170 8 14 SUPER
5 3295 33 340 16 14 HYPER
6 3695 66 340 16 14 UBER
7 1720 25 170 4 14 SPECIAL
8 1995 50 85 2 14 SUPER
9 2225 50 210 8 14 SUPER
12 2605 66 210 8 14 MEGA
13 2045 50 130 4 14 SUPER
14 2295 25 245 8 14 MEGA
16 2225 50 130 4 14 SUPER
17 1595 33 85 2 14 SPECIAL
18 2325 33 210 4 15 MEGA
19 2095 33 250 4 15 SUPER
20 4395 66 452 8 14 UBER
... ... ... ... ... ... ...

The TestData table has more than 1000 rows.

TestData: computers_test1
id price speed hd ram screen
10 2575 50 210 4 15
11 2195 33 170 8 15
15 2699 50 212 8 14
29 3095 33 340 16 14
30 3244 66 245 8 14
38 3795 66 500 8 14
45 3495 50 340 16 14
46 2695 33 245 8 14
48 1749 25 120 4 14
51 2499 33 170 4 14
52 2395 33 130 4 14
59 2945 66 210 8 17
65 2195 66 85 2 14
66 1495 25 170 4 14
70 3095 66 245 8 14
86 1999 33 120 8 14
91 2975 50 210 4 17
92 2145 66 130 4 14
93 2420 33 170 8 15
94 2505 50 210 8 14
104 2999 66 330 4 15
... ... ... ... ... ...

SQL Call

Output

 message                                                                                 
 --------------------------------------------------------------------------------------- 
 Successful!                                                                            
 The final result is successfully stored in the table specified in OutputTable argument.
SELECT * FROM knn_output_1 ORDER BY 1;
 id   computer_category prob               
 ---- ----------------- ------------------ 
   10 mega                             1.0
   11 super                            1.0
   15 mega              0.7515842570160136
   29 hyper                            1.0
   30 hyper             0.9868332664440534
   38 uber                             1.0
   45 uber              0.8872700371272975
   46 mega              0.8007186591491793
   48 special           0.6572238590173166
   51 mega                             1.0
   52 mega                             1.0
   59 hyper                            1.0
  ...  ...                             ...

Download a zip file of all examples and a SQL script file that creates their input tables from the attachment in the left sidebar.