TD_KNN Neighbors Example | kNN | Teradata Vantage - Example: Using TD_KNN with Neighbors - 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
lifecycle
latest
Product Category
Teradata Vantageā„¢

TD_KNN Input Table for Neighbors

Id MSSubClass MSZoning LotFrontage LotArea ... SaleCondition SalePrice
1 60 RL 65 8450 ... Normal 208500
2 20 RL 80 9600 ... Normal 181500
3 60 RL 68 11250 ... Normal 22350
4 70 RL 60 9550 ... Abnormal 140000
5 60 RL 84 14260 ... Normal 250000
... ... ... ... ... ... ... ...

Example: TD_KNN SQL Call for Neighbors

SELECT * FROM TD_KNN(
ON housing_train AS TestTable PARTITION BY ANY
ON housing_train AS TrainingTable DIMENSION
USING     
k(5)
InputColumns('[1:5]') 
IDColumn('sn')     
ModelType('Neighbors')  
) AS dt;   

TD_KNN Output Table for Neighbors

sn neighbor_id1 neighbor_id2 neighbor_id3 neighbor_id4 neighbor_id5
1 106 28 27 18 1
2 23 55 2 24 15
3 3 83 134 81 33
4 4 5 66 35 87
5 35 4 5 87 66