Multivariate logistic regression in Python

 Multivariate logistic regression


Difference between single variate and multivariate regression : 

Suppose we have data of the customer will buy insurance or not? Here you can see your prediction or target is only yes or no. you can also say that 0 or 1 . 

now suppose you have to  build model in which you have to decide which party a person is going to vote for? so there are many target value for this like democratic,republic,independent and many more,Here you have more then two possible outcome so its called  multivariate regression.

Multivariate logistic regression in Python:

Here problem is  given that we have hand written digit(0 to 9) data set and we have to build machine learning model that predict the which digit is it.

So you can clearly notice that our target value is 0 to 9 which means total 10 possible outcome. so it is the example of Multivariate regression. We will use logistic regression for this.


First of all import library


Now we load the data set from the sklearn library and check the directory of data



Lest check how actually looks image 



It is actually a 1D array which contain 64 element. 

If you want to plot this array then 



Now you can see that 1st image look like zero and 2nd look like one.

Lest build the model



You can see our model is 96% accurate. It's a pretty good number.

confusion matrix :

You can also check where our model predict the wrong digit using confusion matrix method.


You can better visualise the confusion matrix by plotting it 



Here lets say truth value is 8 but our model predict 6 one time except the diagonal where ever you see the number which is wrong prediction done by over model.  






Comments

Popular posts from this blog

Decision tree for titanic dataset in Python

K Means Cluster Algorithm