Predictions Logistic Regression model using fitglm

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

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

Thank you for your answer! I understand now that I am indeed fitting a linear model, and I think that for this data that model is appropriate. Regarding the term 'success', I am not sure if I understand the documentation correctly. In my case, I have two classes, and my model is:
model = 'A ~ B + C + D + E + B:C + B:D + B:E'
The matrix 'data' in 'mdl = fitglm(data,modelspec,'Distribution','binomial')' consists of 5 columns (A,B,C,D,E), of which A consists of 0's and 1's, 0 = class 1, 1 = class 2. So by 'positive class', I meant 'class 2'. Is that what they mean by 'success' as well?
@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)

Products

Release

R2021b

Asked:

Eva
on 18 Oct 2021

Commented:

on 30 Oct 2021

Community Treasure Hunt

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

Start Hunting!