Implementing linear regression in Python (linear regression)

Source: Internet
Author: User

1 What is linear regression

The relationship between the dependent variable and several independent variables is determined, and the linear relation model is constructed to predict the dependent variable

2 Linear regression principle

Least squares OLS (ordinary learst squares)

The minimum squared error between the Y and the actual value y of the model

Gradient Descent

I don ' t know

3 Implementing linear regression in Python

Import Sklearn  from Import Linear_model
== Lm.fit (x, y)
The model can be trained #将训练集放入x, y
x = Features
features = [A,b,c,d]

Usually x is more than one variable, or it can be combined into a model by different features, so that the model can have more than one. It is possible to judge the model more rationally by evaluating the individual models.

The data set needs to be divided into training set and test set for evaluation, training model in training set, test set evaluation error

Data sets can be divided into test sets multiple times during the evaluation process, often using cross-examination to reduce randomness, so that data in the dataset can be evaluated as a test set

 from Import  = 5,scoring ="neg_mean_absolute_error")
#通常使用他们的平均值衡量
Import NumPy as NP
Print (Np.mean (cross_val_score (LM,X,Y,CV = 5,scoring = "Neg_mean_absolute_error"))
    • MAE=, the corresponding scoring parameter is ' Neg_mean_absolute_error '
    • MSE=/n, the corresponding scoring parameter is ' Neg_mean_squared_error '

By cross-examination, we can test the scores of each model in different x combinations, and choose a better model to predict Y

Model.predict (something)

Implementing linear regression in Python (linear regression)

Related Article

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.