# How can I improve the accuracy of my logistic regression code, which tests the accuracy using the 10-fold cross-validation technique?

How can I improve the accuracy of my logistic regression code, which tests the accuracy using the 10-fold cross-validation technique? I have implemented this code using glmfit and glmval. The desired accuracy is somewhat higher and it requires the parameters to be found using maximum likelihood estimator. Also, when I run this code in MATLAB, I get the following error

Warning: X is ill conditioned, or the model is overparameterized, and some coefficients are not identifiable. You should use caution in making predictions. In glmfit at 245 In LR at 8

The code is:

function LR( X,y)
y(y==-1)=0;
X=[ones(size(X,1),1) X];
disp(size(X,2));
indices = crossvalind('Kfold',y,10);
for i = 1:10
test = (indices == i); train = ~test;
b = glmfit(X(train,:),y(train),'binomial','logit');
y_hat= glmval(b,X(test,:),'logit');
y_true=y(test,:);
error(i)=mean(abs(y_true-y_hat));
end
accuracy=(1-error)*100;
fprintf('accuracy= %f +- %f\n',mean(accuracy),std(accuracy));
end
• I am voting to leave this open. The question contains code, but isn't really about code. – Peter Flom Apr 6 '19 at 10:59

## 1 Answer

The MATLAB error tells you what is going on - at least possibly - you have either too many variables or some that are creating partial or complete separation. So, you need to remove some variables.

How to improve the fit? Sorry, but without a lot more information, this is going to be guesswork but my guess is that the only way to improve your fit will be go get more data or better variables or a better model.