Predictions Logistic Regression model using fitglm

62 views (last 30 days)
Eva
Eva on 18 Oct 2021
Commented: Ive J on 30 Oct 2021
I created a logistic regression model with four continuous variables as input, using the function fitglm for binary classification. The functions 'predict' and 'feval' say in their documentation that they are only for linear regression models, but when I apply them on my model they do work. I am unsure how to interpret the output. My questions are:
  1. Is the output of both predict and feval the probability that the sample belongs to the positive class?
  2. Is there a different function for model evaluation that is a better fit for my model?
My code:
mdl = fitglm(data,modelspec,'Distribution','binomial');
out = predict(mdl,testdata);

Accepted Answer

the cyclist
the cyclist on 18 Oct 2021
I have a couple of comments, before answering your specific questions.
First, you might benefit by reading up a little bit on generalized linear models (e.g. on this wikipedia page). You seem to think your model is not linear, but it is. A logistic regression is a linear model -- because you use a linking function to make it so.
In particular, the word "linear" in linear regression refers to the coefficients, not the terms themselves. For example, fitting a model of the form
y = alpha + beta1*x + beta2*x.^2
would be a linear regression. It's linear in alpha and beta (not in x).
Fitting the model
y = a * exp(b*x)
is a non-linear model, because it is not linear in b.
Second, by virtue of the fact that you used fitglm, you have fit a linear model. Whether that was the most appropriate model for your data is impossible to know, without seeing your data. (That is basically the answer to your second question.)
The answer to your first question is in this section of the documentation for predict. I'm pretty sure that when you say "positive", you mean the same as "success" in the documentation, so the answer to your question is yes.
  3 Comments
Ive J
Ive J on 30 Oct 2021
@Eva de Bock On a side note, you should be aware that the output of your model is predictive probability of your so-called 'success', and by definition logisitc regression is not a classifier (no '0' or '1' in the output), but generates a spectrum of values (in range of (0, 1)). In your case, predict function gives you the predicted probabilities of A using the model you specified above. A value of 0.99 can be safely regarded as success and a value close to 0 as failure. You may find also this elegant discussion by Frank Harrell of interest: https://www.fharrell.com/post/classification/

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by