フィルターのクリア

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 Center および File ExchangeSimulink Environment Customization についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by