[DL] Logical regression of machine learning algorithms

Source: Internet
Author: User
Tags min

Logistic regression (logistic Regression, LR), also known as logistic regression analysis, is one of the classification and prediction algorithms. The probability of future results is predicted by the performance of historical data. For example, we can set the probability of a purchase as the dependent variable, setting the user's characteristic attributes, such as gender, age, registration time, and so on as arguments. predict the probability of purchase based on feature attributes.

Predictive models for logistic regression:

Logistic regression is not a regression problem, but a two classification problem, because the variable is not 0 or 1, then we naturally think that the probability function obeys the Bernoulli distribution, and the exponential form of the Bernoulli distribution is a sigmoid function.
The function hθ (x) indicates the probability that the result takes 1, then the probabilities for the classifications 1 and 0 are:

The experiment code is as follows:

Import NumPy as NP import Matplotlib.pyplot as PLT from Sklearn import Linear_model, Datasets # import some data to play
With Iris = Datasets.load_iris () X = iris.data[:,: 2] # We have take the first and the first and the features. Y = Iris.target h =. # # step size in the mesh Logreg = Linear_model.
Logisticregression (c=1e5) # We create an instance of Neighbours Classifier and fit the data. Logreg.fit (X, Y) # Plot the decision boundary.
For that, we'll assign a color to each of the # in the mesh [X_min, X_max]x[y_min, Y_max]. X_min, X_max = x[:, 0].min ()-. 5, x[:, 0].max () +. 5 y_min, Y_max = x[:, 1].min ()-. 5, x[:, 1].max () +. 5 xx, yy = np.me Shgrid (Np.arange (X_min, X_max, h), Np.arange (Y_min, Y_max, h)) Z = Logreg.predict (Np.c_[xx.ravel (), Yy.ravel ()]) # Put th e result into a color plot Z = Z.reshape (Xx.shape) plt.figure (1, figsize= (4, 3)) Plt.pcolormesh (xx, yy, Z, Cmap=plt.cm.pai Red) # Plot also the training points plt.scatter (x[:, 0], x[:, 1], c=y, edgecolors= ' K ', cmap=plt.cm.paired) plT.xlabel (' sepal length ') Plt.ylabel (' sepal width ') plt.xlim (Xx.min (), Xx.max ()) Plt.ylim (Yy.min (), Yy.max ()) Plt.xticks (()) Plt.yticks (()) Plt.show ()

The test results are as follows:

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.