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)
X=[ones(size(X,1),1) X];
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');
fprintf('accuracy= %f +- %f\n',mean(accuracy),std(accuracy));
  • 3
    $\begingroup$ I am voting to leave this open. The question contains code, but isn't really about code. $\endgroup$ – Peter Flom Apr 6 '19 at 10:59

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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.