use fitcknn, fitcsvm

11 views (last 30 days)
Tu Nguyen
Tu Nguyen on 11 May 2022
Answered: arushi on 29 Aug 2024
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);

Answers (1)

arushi
arushi on 29 Aug 2024
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!

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!