how to implement KNN classification in simulink

조회 수: 2 (최근 30일)
pavan sunder
pavan sunder 2016년 12월 14일
댓글: Walter Roberson 2022년 4월 10일
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.

답변 (1개)

Vandana Rajan
Vandana Rajan 2016년 12월 19일
편집: Vandana Rajan 2016년 12월 20일
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
Walter Roberson
Walter Roberson 2022년 4월 10일
Note: these days, Simulink does support string objects as inputs.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Modeling에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by