This repository was archived by the owner on Jun 27, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeierabend_philipp_classification.m
More file actions
86 lines (76 loc) · 3.35 KB
/
Copy pathfeierabend_philipp_classification.m
File metadata and controls
86 lines (76 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
function diagnosis = feierabend_philipp_classification(RR_intervals, pulse, avg_RR, max_RR, min_RR, std_RR, dataset_label, model)
% Default diagnosis
diagnosis = 'Unknown';
probability = zeros(1, 3); % Array to hold probabilities for SR, CHF, ARR
% Error checks for the input values
if isempty(RR_intervals) || length(RR_intervals) < 2
disp('Error: Not enough RR_intervals detected.');
diagnosis = 'Error: Not enough RR_intervals';
return;
elseif isempty(pulse)
disp('Error: pulse is empty.');
diagnosis = 'Error: pulse is empty';
return;
elseif isempty(avg_RR)
disp('Error: avg_RR is empty.');
diagnosis = 'Error: avg_RR is empty';
return;
elseif isempty(max_RR)
disp('Error: max_RR is empty.');
diagnosis = 'Error: max_RR is empty';
return;
elseif isempty(min_RR)
disp('Error: min_RR is empty.');
diagnosis = 'Error: min_RR is empty';
return;
elseif isempty(std_RR)
disp('Error: std_RR is empty.');
diagnosis = 'Error: std_RR is empty';
return;
end
% Check for NaN values in the input parameters
if any(isnan([pulse, avg_RR, max_RR, min_RR, std_RR]))
disp('Error: One or more input values are NaN.');
diagnosis = 'Error: One or more input values are NaN';
return; % No classification if NaN values are present
end
% Output the features for debugging (optional)
disp('Health Bot: Input features for classification:');
disp(['Pulse: ', num2str(pulse)]);
disp(['Avg RR: ', num2str(avg_RR)]);
disp(['Max RR: ', num2str(max_RR)]);
disp(['Min RR: ', num2str(min_RR)]);
disp(['Std RR: ', num2str(std_RR)]);
% Feature array for classification
features = [pulse, avg_RR, max_RR, min_RR, std_RR];
% Use the trained model for prediction
try
predicted_label = predict(model, features); % Predicted label (numerical)
catch
disp('Error: Model prediction failed.');
diagnosis = 'Error: Model prediction failed';
return;
end
% Convert numeric predicted label to text label
predicted_label_num = str2double(predicted_label{1}); % Convert string to number
% Map the numeric predictions back to their corresponding labels
label_map = {'SR', 'ARR', 'CHF'};
predicted_label_str = label_map{predicted_label_num};
% Always display the predicted label with emphasis
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');
disp(['%%%%%%%%%%%%%%%%%%%%%%% The predicted classification is: ', upper(predicted_label_str), ' %%%%%%%%%%%%%%%%%%%%%%%']);
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');
% If the dataset label is 'unknown', output a specific message
if strcmp(dataset_label, 'unknown')
disp('Traindata: The classification is unknown, caused in testdata.');
else
% Compare classification with actual dataset label
if strcmp(predicted_label_str, dataset_label)
disp(['Traindata: The classification is correct! The dataset is: ', dataset_label]);
else
disp(['Traindata: The classification is incorrect. The correct dataset is: ', dataset_label]);
end
end
% Return the predicted diagnosis
diagnosis = predicted_label_str;
end