Simple and crude understanding and implementation of machine learning linear regression (two): Preliminary using linear regression api, Case

Linear Regression

learning target

  • Ownership in the implementation process of linear regression
  • Application LinearRegression or SGDRegressor achieve regression prediction
  • We know the assessment criteria and formulas regression algorithm
  • Overfitting know the causes and solutions underfitting
  • We know principle ridge regression and linear regression differences
  • Application Ridge achieve regression prediction
  • Application joblib achieve saving and loading models

2.2 linear regression api initial use

Here Insert Picture Description

1 linear regression API

  • sklearn.linear_model.LinearRegression()
    • LinearRegression.coef_: regression coefficient

2 Examples

[Image dump the chain fails, the source station may have security chain mechanism, it is recommended to save the picture down uploaded directly (img-mtBiKTz6-1583244220720) (../ images /% E7% BA% BF% E6% 80% A7% E5 % 9B% 9E% E5% BD% 92api% E4% BD% BF% E7% 94% A8% E4% B8% BE% E4% BE% 8B.png)]

2.1 Analysis of step

  • 1. Obtain data set
  • 2. Basic data processing (omitted in this case)
  • 3. The feature works (in this case omitted)
  • 4. Machine Learning
  • The model assessment (omitted in this case)

2.2 Code Process

  • Import module
from sklearn.linear_model import LinearRegression
  • Construct a data set
x = [[80, 86],
[82, 80],
[85, 78],
[90, 90],
[86, 82],
[82, 90],
[78, 80],
[92, 94]]
y = [84.2, 80.6, 80.1, 90, 83.2, 87.6, 79.4, 93.4]
  • Machine learning - training model
# 实例化API
estimator = LinearRegression()
# 使用fit方法进行训练
estimator.fit(x,y)

estimator.coef_

estimator.predict([[100, 80]])
Published 596 original articles · won praise 790 · Views 100,000 +

Guess you like

Origin blog.csdn.net/qq_35456045/article/details/104642833