How can I implement KNN ? I want to have user input and data from excel sheet compared.
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuesta aceptada
KSSV
el 13 de Mayo de 2022
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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!