TD_KNN Regression Example | kNN | Teradata Vantage - Example: Using TD_KNN To Predict Weight Based on Height and Age - Analytics Database

Database Analytic Functions

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Analytics Database
Release Number
17.20
Published
June 2022
Language
English (United States)
Last Update
2024-10-04
dita:mapPath
gjn1627595495337.ditamap
dita:ditavalPath
ayr1485454803741.ditaval
dita:id
jmh1512506877710
Product Category
Teradata Vantage™

TD_KNN Input Table for Regression Example

Person_train
id height age weight
0 5 32 67
1 5.11 45 98
2 5.9 46 78
3 4.8 35 86
4 5.8 22 70
... ... ... ...

Example: TD_KNN SQL Call for Regression

SELECT * FROM TD_KNN(
ON person_test AS TestTable PARTITION BY ANY
ON person_train AS TrainingTable DIMENSION
USING
K(2)
ResponseColumn('weight')
InputColumns('height','age')
IDColumn('id')
ModelType('regression')
EmitNeighbors('true’)
EmitDistances('true')
) AS dt ;

TD_KNN Output Table for Regression

id prediction neighbor_id1 neighbor_dist1 neighbor_id2 neighbor_dist2
11 88 4 0.7 2 1.004
12 80 8 20.00 4 41.00