GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Disease_Prediction_MachineLearning_MATLAB/train_all_models.m at main · mrsudo404/Disease_Prediction_MachineLearning_MATLAB

Expand file tree

/

train_all_models.m

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
57 lines (45 loc) · 1.68 KB
/

train_all_models.m

Copy path

File metadata and controls

57 lines (45 loc) · 1.68 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
% Load dataset
data = readtable('diabetes_dataset.csv');
% Prepare features and labels
X = table2array(data(:, 1:end-1));
y = table2array(data(:, end));
% Convert labels to binary (0 and 1)
y = double(categorical(y));
y = y - min(y); % Ensures labels are 0 or 1
% Train-test split
cv = cvpartition(y, 'HoldOut', 0.3);
X_train = X(training(cv), :);
y_train = y(training(cv));
X_test = X(test(cv), :);
y_test = y(test(cv));
% Normalize features
mu = mean(X_train);
sigma = std(X_train);
X_train_norm = (X_train - mu) ./ sigma;
X_test_norm = (X_test - mu) ./ sigma;
% --- Train Logistic Regression ---
log_model = fitglm(X_train_norm, y_train, 'Distribution', 'binomial');
save('logistic_model.mat', 'log_model');
% --- Train SVM ---
svm_model = fitcsvm(X_train_norm, y_train, 'KernelFunction', 'rbf', 'Standardize', false);
save('svm_model.mat', 'svm_model');
% --- Train Linear Regression as Classifier ---
lin_model = fitlm(X_train_norm, y_train);
save('linear_model.mat', 'lin_model');
% --- Save normalization stats ---
save('mu_sigma.mat', 'mu', 'sigma');
% --- Generate and save confusion matrices ---
log_preds = round(predict(log_model, X_test_norm));
figure; confusionchart(y_test, log_preds);
title('Confusion Matrix - Logistic Regression');
saveas(gcf, 'confusion_logistic.png');
svm_preds = predict(svm_model, X_test_norm);
figure; confusionchart(y_test, svm_preds);
title('Confusion Matrix - SVM');
saveas(gcf, 'confusion_svm.png');
lin_probs = predict(lin_model, X_test_norm);
lin_preds = double(lin_probs >= 0.5);
figure; confusionchart(y_test, lin_preds);
title('Confusion Matrix - Linear Regression');
saveas(gcf, 'confusion_linear.png');
disp('Training complete. Models and figures saved.');
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.