How can I implement KNN ? I want to have user input and data from excel sheet compared.
3 次查看(过去 30 天)
显示 更早的评论
Basically I want to have a code that compares input with excel sheet data if said data is there then I want to return that if not I'd like to find the closet value to it (nearest neighbor). It would also return the difference between the nearest neighbor and input, how could I go about it?
Ex:
Userinput-- my patient weighs 115lbs and is 33 yrs old
data -- patients in hospital x weigh (97lbs and is 15 yrs old, 140lbs and is 30yrs old, 105lbs and is 25 yrs old, 210 and is 67yrs old )
Answer: is similar to patient that weighs 105lbs and is 25 yrs old the difference between them is 8 yrs 10lbs
Any ideas are welcome, thank you! If anymore explanation is needed I would be happy to try and further explain!
0 个评论
采纳的回答
KSSV
2022-5-13
weight = [971; 1401; 105; 210] ;
age = [15; 30 ; 25 ; 67] ;
data = table(weight,age)
% user input
input_weight = 115 ;
input_age = 33 ;
idx = knnsearch([data.weight data.age],[input_weight input_age]) ;
iwant = [data.weight(idx) data.age(idx)]
thediff = abs(iwant-[input_weight input_age])
Note that creating table is optional;, you can go ahead with arrays also.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!