train model using cvpartition

In this project, i am required to investigate the effectiveness of the logistic regression classifier in heart disease detection
i have to do this: function [theta, lambda] = trainLRModel(x, y, lambda_values)
by using cvpartition. and applies 10-fold cross validation to choose the best lambda value among lambda_values.
how can i use cvpartition with my logistic regression classifier model ?
this is my code so far
%% ******************* Loading Data **********************
data = xlsread('heart.csv');
disp('The dataset was loaded sucessfully!');
X = data(:,1:end-1);% features
y = data(:,end);% class labels
%disp(X);
%disp(y);
%disp(data);
m = size(X,2);
%% *******************feature Normalization**************************
for i=1:m,
X(:,i) = featureNormalization(X(:,i));
end
%disp(X);
%% ****************** Calculate Cost and Gradient *******************
lambda = 1;
theta = zeros(size(X, 2), 1);
%disp(size(initial_theta));
%X = [ones(size(X,1),1) , X];
%disp(size(X));
[cost, grad] = computeLRCost(X, y, theta,lambda);
disp('The cost when theta values initialized to zeros');
disp(cost);
%% ******************* Learn Theta Values *******************
theta = learnLRTheta(X, y, lambda);
%disp (theta);
%% ******************* train LR Model *******************
lambda_values = [0 0.001 0.003 0.01 0.03 0.1 0.3 1 3 10 20 30 40]';
%[theta, lambda] = trainLRModel(X, y, lambda_values);

Answers (0)

Asked:

on 30 Nov 2019

Community Treasure Hunt

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

Start Hunting!