use fitcknn, fitcsvm

조회 수: 11 (최근 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 CenterFile Exchange에서 AI for Signals에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by