Machine Learning by Andrew Ng --- Logistic Regression of Multi-class Classification

We will use Logistic Regression to recognize the number 1-10.


Loading data,Plotting data.as the picture below:

Machine Learning by Andrew Ng --- Logistic Regression of Multi-class Classification_第1张图片



Vectorizing regularized logistic regression

Machine Learning by Andrew Ng --- Logistic Regression of Multi-class Classification_第2张图片

Machine Learning by Andrew Ng --- Logistic Regression of Multi-class Classification_第3张图片


Then learn the theta:


Predicting:

Machine Learning by Andrew Ng --- Logistic Regression of Multi-class Classification_第4张图片


It is important to understand the final max function ,if you make your data which you want to predict by rows, then you should remember ,like the max function in the picture above ,when finished sigmoid function inside of max function,the result matrix owns ten columns ,which means that every column shows the probability of your data witch you want to predict might be .i.e.the second column show the probability of your data might be 1(note: the first column represent 10). 


After get the result Matrix,the max function return the biggest number of each row ,also say the biggest probabilities.

你可能感兴趣的:(Machine Learning by Andrew Ng --- Logistic Regression of Multi-class Classification)