how to implement KNN classification in simulink

3 visualizaciones (últimos 30 días)
pavan sunder
pavan sunder el 14 de Dic. de 2016
Comentada: Walter Roberson el 10 de Abr. de 2022
How to implement KNN classification in simulink. I used fitcknn and predict functions in my script file,but the same cannot be used in matlab function block in simulink.
Also my class labels (response variable) are in the form of strings. i am not able pass string inputs in simulink.
for ex: suppose i train my KNN with following data
my predictor values are p=[1 2 3]
my response values are r=['one','two','three'];
my test input is 3
the commands i used in script file are:
mdl=fitcknn(p,r);
y=predict(mdl,3);
the answer after running the script was
y=three (expected as per training data)
The same result i want to simulate in simulink. Kindly suggest me the right approach.

Respuestas (1)

Vandana Rajan
Vandana Rajan el 19 de Dic. de 2016
Editada: Vandana Rajan el 20 de Dic. de 2016
Hi Pavan,
1. Since Simulink does not support string inputs, you can convert class labels to digits. Like Class A can be represented by 1, Class B by 2 and so on.
2. 'fitcknn' and 'predict' functions are not supported for standalone code generation, you can use 'coder.extrinsic' declaration for extrinsic functions. The link below can give you more details about 'coder.extrinsic'
https://www.mathworks.com/help/simulink/slref/coder.extrinsic.html
3. Since 'fitcknn' outputs a model, which is an object of type 'ClassificationKNN' and not a numeric output, MATLAB function block will not support it. Hence you may go for using 'system objects' in a 'MATLAB system' block instead of MATLAB function block. Use 'interpreted execution' mode for the system block.
You may use the link below for more details on system block
https://in.mathworks.com/help/simulink/ug/what-is-matlab-system-block.html
  1 comentario
Walter Roberson
Walter Roberson el 10 de Abr. de 2022
Note: these days, Simulink does support string objects as inputs.

Iniciar sesión para comentar.

Categorías

Más información sobre Modeling en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by