use fitcknn, fitcsvm

4 ビュー (過去 30 日間)
Tu Nguyen
Tu Nguyen 2022 年 5 月 11 日
回答済み: arushi 2024 年 8 月 29 日
Hi all,
I have a template ECG signal, and I have 40 test of ECG. Now I have to use function fitcknn and fitcsvm to do machine learning classification for statistic.
But I dont know how to run the code, I put like this but the code returned error
I really appreciate for your help
M1 = fitcknn(template,ecg_test_rand);
M2 = fitcsvm(template,ecg_test_rand);

回答 (1 件)

arushi
arushi 2024 年 8 月 29 日
Hi Tu Nguyen,
I understand that you are trying to classify ECG data using “fitcknn” and “fitcsvm” inbuilt function.
To classify ECG data using the built-in functions “fitcknn” and “fitcsvm”, you can refer to the provided code snippet:
% Load the data into the MATLAB workspace from the file
a = load("ecg.csv")
% Divide the data into Training data and Testing Data. You can try %different algorithms for data division
cv = cvpartition(size(a,1),'HoldOut',0.3);
idx = cv.test;
% Separate the training and test data
dataTrain = a(~idx,:);
dataTest = a(idx,:);
% Separate the input data and output data from the training data
dataTrainX = dataTrain(:,(1:end-1));
dataTrainY = dataTrain(:,end);
% Train the Model using the built-in functions
Mdl = fitcknn(dataTrainX, dataTrainY);
Md2 = fitcsvm(dataTrainX, dataTrainY);
For more information on “fitcknn” function, you can refer to the below Mathworks documentation link: -
For more information on “‘fitcsvm” function, you can refer to the below Mathworks documentation link: -
I hope this helps!

カテゴリ

Help Center および File ExchangeAI for Signals についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by