Hi All,

there was an interesting article on building Logistic Regression classifier from scratch

However i need to build multinomial LR … how should this code be modified in order to achieve it from scratch

Thanks

Swati

Hi All,

there was an interesting article on building Logistic Regression classifier from scratch

However i need to build multinomial LR … how should this code be modified in order to achieve it from scratch

Thanks

Swati

Hi @swati0205 ,

Multinomial logistic regression works in a little bit different way.

I am listing down the steps below for you to understand how it works. for you to understand lets take a scenario.

Suppose you have to predict the appettite(High/ Medium/ Low) of a person based on eating frequency, size of per meal and meal preference(veg/ non-veg/eggetarian). We will go ahead something like below.

- Clean the data(of-course), change the categorical independent variable into dummy variable and do EDA
- second step is to relevel the predictor variable appetite. this is we do to make one of choice(high/medium/low) as baseline
- You use multinom function(not glm in this case) everything else is same.
- after creating the first model with multinom function you get the coefficients and standard error of each independent variable.
- In multinom function, p-value is not automatically calculated so you have to calculate that from coefficients and standard errors (will provide you the link below for your understanding)
- After that your normal variable reduction goes with P-value and VIF.
- As a result of multinom function, you get coefficient of all choice of dependent but the one you use the baseline for.
- From coefficients, you have to calculate the probability function.
- this probability function will tell you the probability of each choice based on the test data you have.
- model evaluation is almost same a logistic regression.

Above the very high level explanation of it. If you want to understand more. Please follow below link for it. it has been explained beautifully.

https://stats.idre.ucla.edu/r/dae/multinomial-logistic-regression/