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

Teradata® VantageCloud Lake

Deployment
VantageCloud
Edition
Lake
Product
Teradata Vantage
Published
January 2023
ft:locale
en-US
ft:lastEdition
2024-12-11
dita:mapPath
phg1621910019905.ditamap
dita:ditavalPath
pny1626732985837.ditaval
dita:id
phg1621910019905

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