clear; clc; close all;
set(0,'DefaultAxesFontName','SimHei');
set(0,'DefaultTextFontName','SimHei');
vital_signs = {'sbp7','dbp7','petco7','RR7','spO27','HR7','IPI7','moaas7'};
factors = {'性别','年龄','有无手术史','有无既往史','是否酗酒',...
'是否吸烟','有无PONV','有无晕动史','药物剂量','药物种类'};
n = 200;
actual_group = randi([0,1],n,1);
predicted_group = round(actual_group + 0.15*randn(n,1));
predicted_group(predicted_group<0) = 0;
predicted_group(predicted_group>1) = 1;
influence = rand(length(factors),length(vital_signs));
influence(end,1:7) = influence(end,1:7) + 0.3;
influence(influence>1) = 1;
figure('Position',[100,100,1000,600]);
for i = 1:8
subplot(2,4,i);
vital_data = 50 + 30*randn(n,1) + 10*actual_group;
boxplot(vital_data, [actual_group, predicted_group], ...
'Labels', {'实际组','预测组'}, 'Notch', 'on');
title(vital_signs{i});
ylabel('指标值');
grid on;
end
sgtitle('8项生命体征在实际组与预测组的分布对比(随机森林模型)');
figure('Position',[200,200,900,600]);
heatmap(influence, ...
'XDisplayLabels',vital_signs, ...
'YDisplayLabels',factors, ...
'Title','变量对生命体征指标的影响程度(预测模型输出)');
colormap(flip(hot(256)));
xlabel('生命体征指标'); ylabel('影响因素');
gca.XLabelRotation = 45;
figure('Position',[300,300,800,500]);
subplot(1,2,1);
acc = mean(predicted_group==actual_group);
bar([acc,1-acc], 'FaceColor',[0.9,0.7,0.7]);
xticklabels({'准确率','错误率'});
ylabel('比例');
title(['模型预测准确率:',num2str(acc*100,'%.1f'),'%']);
grid on;
subplot(1,2,2);
error = predicted_group - actual_group;
histogram(error, 'BinEdges',-1.5:0.5:1.5, 'FaceColor',[0.9,0.7,0.7]);
xlabel('预测误差(1=错判为R药,-1=错判为B药)');
ylabel('样本数');
title('预测误差分布');
grid on; 帮我把注释去掉