Clear Filters
Clear Filters

Training, validating, and testing model.

7 views (last 30 days)
NeedHelp55 on 23 May 2024
Answered: Star Strider on 23 May 2024
I have written three linear regression models and would like to know how to train, validate, and thest them with a random 60 20 20 split. any help would be much appreciated. here is the code.
PTT = filtered_BP_Data(:, 1);
systolicBP = filtered_BP_Data(:, 2);
diastolicBP = filtered_BP_Data(:, 3);
avgBP = filtered_BP_Data(:, 4);
lm1 = fitlm(PTT, systolicBP);
% plot PTT vs systolic BP
scatter(PTT, systolicBP, 'x');
hold on;
regressionLine1 = lm1.Coefficients.Estimate(1) + lm1.Coefficients.Estimate(2) * PTT;
plot(PTT, regressionLine1, '-r');
xlabel('PTT (ms)');
ylabel('Systolic Blood Pressure (mmHg)');
title('Average PTT vs Systolic BP');
legend('Data Points', 'Location', 'best');
grid on;
hold off;
lm2 = fitlm(PTT, diastolicBP);
% plot PTT vs diastolic BP
scatter(PTT, diastolicBP, 'x');
hold on;
regressionLine2 = lm2.Coefficients.Estimate(1) + lm2.Coefficients.Estimate(2) * PTT;
plot(PTT, regressionLine2, '-r');
xlabel('PTT (ms)');
ylabel('Diastolic Blood Pressure (mmHg)');
title('Average PTT vs Diastolic BP');
legend('Data Points', 'Location', 'best');
grid on;
hold off;
lm3 = fitlm(PTT, avgBP);
% plot PTT vs avg BP
scatter(PTT, avgBP, 'x');
hold on;
regressionLine3 = lm3.Coefficients.Estimate(1) + lm3.Coefficients.Estimate(2) * PTT;
plot(PTT, regressionLine3, '-r');
xlabel('PTT (ms)');
ylabel('Avg Blood Pressure (mmHg)');
title('Average PTT vs Avg BP');
legend('Data Points', 'Location', 'best');
grid on;
hold off;

Answers (1)

Star Strider
Star Strider on 23 May 2024
Perhaps I am missing something in your problem statement, however linear regressions such as that done by fitlm is a least-squares approach and entirely deterministic, not ‘training’. There is nothing heuristic about it. You should get the same result (within the limits of floating-point calculation precision) every time you run it using the same data. If you use subsets of the entire data set, you will of course get different regression coefficients depending on the data you use, and they may be different (I would expect them to be different) from the values using the entire data set. Also, if you use the predict function to calculate the ‘regressionLine’ values, it will also supply the confidence limits on the regression.
With respect to the systolic, diastolic, and mean blood pressure, note that the mean blood pressure (averaged over the entire cardiac cycle) is approximately one-third the difference of the systolic and diastolic pressures, not their arithmetic mean, so —
SBP = 120;
DBP = 80;
meanBP = (SBP - DBP)/3 + DBP
meanBP = 93.3333
not —
avgBP = mean([SBP DBP])
avgBP = 100




Community Treasure Hunt

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

Start Hunting!