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)