algorithm. The basic idea of the gradient rise method is that to find the maximum value of a function, the best way is to look for it along the gradient direction of the function. To learn more about this approach, it is recommended to look at Andrew Ng's machine learning course, and remember that in the second section the gradient descent method is the main one, and the gradient rise differs from the minimum value of the function, but the thought is consistent.Two
partial derivative. the gradient grad of the loss function of Logistic regression algorithm is . By constantly updating the weights of x iterations a certain number of times you can get the desired W.Second, algorithm debugging 2.1 gradient descent method algorithmfirst define the functions that import the data Loaddataset (), which makes the data import more convenient. For the convenience of operation, t
to close to 0 (when the coefficients are almost no longer adjusted, then the iterations are meaningless), we constrain alpha to be more than a slightly larger constant term, see code.2) Each iteration, change the order of optimization of the sample. That is, randomly selecting samples to update the regression coefficients. This reduces cyclical fluctuations, because the order of the samples changes so that
optimal regression coefficients, we need to use the optimization algorithm, the most commonly used is the gradient rise method. The idea is that to find the maximum value of a function, the best way is to follow the gradient direction of the function. If the gradient is recorded as Grad (x,y) or, the gradient of the function f (x,y) is represented:Grad (x,y) = =The gradient operator always points to the fastest-growing direction of the function value
a function, and the best way is to search along the gradient of the function.
This formula will be iterated until a certain stop condition is reached. For example, the number of iterations reaches a specified value or the algorithm reaches an acceptable error range.
2: Python code implementation
(1) Use gradient rise to find the optimal number of workers
From numpy import * # load data def loaddataset ()
single instance of the logarithmic result is:Log (P) = Ylog (g (x)) + (1-y) log (1-g (x))This looks a bit like cross-entropy, and adding this to the training data is the last log-like. Of course, the front plus a symbol is the negative log likelihood, the parametric solution is to minimize the negative log likelihood when the corresponding parameter situation. The commonly used method is gradient descent.The following is affixed with a Python Theano
the best way is to search along the gradient of the function.
This formula will be iterated until it reaches a certain stop condition. For example, the number of iterations reaches a specified value or the algorithm reaches a certain allowable error range.
2: Python code implementation
(1) Use gradient rise to find the optimal parameter
From numpy import * # load data def loaddataset (): datamat = []; la
it also represents the probability of y=1, the probability of y=0 is 1-phi (z)Draw a description#! /usr/bin/python Import Matplotlib.pyplotAs PltImport NumPyAs NPDefSigmoid(z):Return1.0/(1.0+np.exp (-Z)) z = Np.arange (-10,10,0.1) p = sigmoid (z) plt.plot (z,p)#画一条竖直线, if you do not set the value of x, the default is 0plt.axvline (x=0, Color=' K ') Plt.axhspan (0.0,1.0,facecolor= ' 0.7 ', Alpha=0.4) # draw a horizontal line, If you do not set the val
same. In addition, it is necessary to feature scale (Features scaling) features before running the gradient descent algorithm.Some options beyond the gradient descent algorithm:In addition to the gradient descent algorithm, there are algorithms that are often used to minimize the cost function, which are more complex and excellent, and typically do not require manual selection of learning rates, and are often faster than gradient descent algorithms. Some examples: conjugate gradient method (co
learned classification interface curve:
Curve between the loss function value and the number of iterations:
Final output result:
It can be seen that when a child's first homework is 20 points and the second homework is 80 points, the probability that the child cannot go to college is 0.6680. Therefore, if the child is used as a binary classification, it means that the child will not be allowed to go to college.
LabCode(Provided on the original webpage ):Copy
by the method of multivariate linear regression. For the case where p takes only 0 and 1, in practice it is not a direct return to p, but rather a monotone continuous probability function pi:
At this point the logistic model is:
Then only the original data should be properly mapped, the regression coefficients can be obtained by linear
likelihood function of θ can be written as follows:
To solve the maximum log likelihood of L (θ:
In order to maximize the likelihood, this method is similar to linear regression that uses gradient descent to calculate the deviation of the number likelihood pair, that is:
Note: The formula for the gradient descent algorithm is as follows. This is a gradient rise. Gradient: = gradient means that the variation value of the two iterations (or the two
Preface: This section exercises the relevant content of the logistic regression, referring to the information for the Web page: http://openclassroom.stanford.edu/MainFolder/DocumentPage.php?course= Deeplearningdoc=exercises/ex4/ex4.html. The training sample given here is characterized by a score of two subjects for 80 students, a sample value of whether the corresponding classmate is allowed to go to uni
Recently turned Peter Harrington "machine Learning Combat", see the Logistic regression chapter a little bit of doubt.After a brief introduction of the principle of logistic regression, the author immediately gives the code of the gradient rise algorithm: The range of the al
(Pass_logistic,newdata=list (sat=400), type = "Response")> Predict.glm (Pass_logistic,newdata=list (sat=700), type = "Response")> sat_x > pred_l > Plot (sat_x,pred_l,type= "L", ylab= "probability", xlab= "Sat_m")The above code explains:A logistic model is fitted through the GLM function and the model result details are obtained through SUMMARY.GLM, where the null deviance and residual deviance are similar
Http://scikit-learn.org/stable/modules/linear_model.html#logistic-regression)5. Implementation and specific examplesMain uses of logistic regression:
Looking for risk factors: Looking for a disease risk factors, etc.;
Prediction: According to the model, the probability of the occurrence of a disease or a
According to Dr. Hangyuan Li's summary of statistical learning three-factor method = model + strategy + algorithm, corresponding to logistic regressionMODEL = conditional probability model based on unipolar function (logical function)Strategy = maximum of prior probability of training samples corresponding to experience lossAlgorithm = Random gradient rise methodThe logistic
See machine learning practices
The main idea of using Logistic regression for classification:
Establish a regression formula for the classification boundary line based on the existing data for classification.
The sigmoid function used for classification:
Sigmoid Function diagram:
Functions of sigmoid:
Multiply all features by a
Please refer to the original English http://www.deeplearning.net/tutorial/logreg.html
here, we will use Theano to implement the most basic classifiers: Logistic regression, and Learn how mathematical expressions are mapped into Theano diagrams. Logistic regression is a linear classifier based on probability, W and
The logistic regression of batch gradient descent can refer to this article: http://blog.csdn.net/pakko/article/details/37878837After reading some Scala syntax, I'm going to look at the parallelization of Mllib's machine learning algorithm, which is logistic regression to find the package Org.apache.spark.mllib.classif
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.