Filter löschen
Filter löschen

how to implement KNN classification in simulink

6 Ansichten (letzte 30 Tage)
pavan sunder
pavan sunder am 14 Dez. 2016
Kommentiert: Walter Roberson am 10 Apr. 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.

Antworten (1)

Vandana Rajan
Vandana Rajan am 19 Dez. 2016
Bearbeitet: Vandana Rajan am 20 Dez. 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 Kommentar
Walter Roberson
Walter Roberson am 10 Apr. 2022
Note: these days, Simulink does support string objects as inputs.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Simulink Environment Customization finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by