Professional Documents
Culture Documents
Types of Arrhythmias
Ventricular tachycardia(VT) is a fast, abnormal heart rate. It starts in your heart's lower chambers,
called the ventricles.
Features
RR The R-R interval: The RR interval is the time between QRS complexes. (normal is between (0.6 to 1
second)
Speed For adults 18 and older, a normal resting heart rate is between 60 and 100
Age 23/89
Gender M/F
Dataset https://github.com/davikawasaki/arrhythmia-ecg-analysis-ai
Load Data
TrainData=readtable('samples-training.xlsx');
TestData=readtable('samples-testing.xlsx');
TrainData.Gender=categorical(TrainData.Gender);
TrainData.Arrhythmia=categorical(TrainData.Arrhythmia);
TestData.Gender=categorical(TestData.Gender);
TestData.Arrhythmia=categorical(TestData.Arrhythmia);
Summary of Data
summary(TrainData)
Variables:
Min 0.52
Median 0.96
Max 2.31
Values:
Min 0.38
Median 0.81
Max 2.53
Values:
Min 0.31
Median 1.19
Max 5.85
Values:
Min 23.00
Median 69.00
Max 89.00
Values:
F 627.00
M 2304.00
Values:
(B 42.00
(N 2819.00
(T 39.00
(VT 31.00
summary(TestData)
Variables:
Values:
Min 0.51
Median 1.31
Max 1.94
Min 0.56
Median 0.97
Max 2.55
Values:
Min 0.22
Median 1.35
Max 2.73
Values:
Min 23.00
Median 75.00
Max 89.00
Values:
F 730.00
M 11.00
Arrhythmia: 741×1 categorical
Values:
(B 12.00
(N 707.00
(T 12.00
(VT 10.00
Histogram of age
histogram(TrainData.Age)
axis tight
xlabel('Age')
ylabel('count')
Histogram of M/F
histogram(TrainData.Gender)
axis tight
xlabel('Gender')
ylabel('count')
Histogram of Arrhythmias
histogram(TrainData.Arrhythmia)
axis tight
xlabel('Gender')
ylabel('count')
histogram(TestData.Age)
axis tight
xlabel('Age')
ylabel('count')
Histogram of M/F
histogram(TestData.Gender)
axis tight
xlabel('Gender')
ylabel('count')
Histogram of Arrhythmias
histogram(TestData.Arrhythmia)
axis tight
xlabel('Gender')
ylabel('count')
Create Model
classificationLearner
trainedModel = trainClassifier(TrainData);
trainPred=trainedModel.predictFcn (TrainData(:,1:5));
Accuracy
MLAccuracytrain =
99.35
figure
confusionchart(TrainData.Arrhythmia,trainPred,'ColumnSummary','column-normalized',...
'RowSummary','row-normalized','Title','Confusion Chart for ML');
testPred=trainedModel.predictFcn (TestData(:,1:5));
Accuracy
MLAccuracytest =
97.84
figure
confusionchart(TestData.Arrhythmia,testPred,'ColumnSummary','column-normalized',...
% Returns a trained classifier and its accuracy. This code recreates the
% generated code to automate training the same model with new data, or to
% Input:
% Output:
% classifier.
% the app, the History list displays this overall accuracy score for
% each model.
% Use the code to train the model with new data. To retrain your
% classifier, call the function from the command line with your original
% For example, to retrain a classifier trained with the original data set
% T, enter:
% use
% yfit = trainedClassifier.predictFcn(T2)
% trainedClassifier.HowToPredict
% This code processes the data into the right shape for training the
% model.
inputTable = trainingData;
response = inputTable.Arrhythmia;
isCategoricalPredictor = [false, false, false, false, true];
% Train a classifier
% This code specifies all the classifier options and trains the classifier.
classificationTree = fitctree(...
predictors, ...
response, ...
'MaxNumSplits', 4, ...
trainedClassifier.ClassificationTree = classificationTree;
trainedClassifier.About = 'This struct is a trained model exported from Classification Learner R2020a.';
% This code processes the data into the right shape for training the
% model.
inputTable = trainingData;
% Perform cross-validation
end