<회귀> 선형 회귀 모델 (LinearRegression)
Data Analyticsㅤ/ㅤMachine Learningㅤ

<회귀> 선형 회귀 모델 (LinearRegression)

선형 회귀 (Linear Regression) 

https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LinearRegression.html

 

- Ordinary Least Squares(OLS) Linear Regression

  • LinearRegression fits a linear model with coefficients w = (w1, …, wp) to minimize the residual sum of squares between the observed targets in the dataset, and the targets predicted by the linear approximation

 

파라미터

- fit_intercept : default=True로 intercept를 반환한다 

- normalize : fit_intercept가 False면 자동으로 무시된다. True면 X가 표준화되고($\frac{x-E(x)}{L2 norm}$) 회귀 모델에 입력된다. 만약 standardize 할거면 StandardScalar 로 전처리 한 후 normalize=False로 학습시키자(fit)

- n_jobs : 학습하는 속도 조절 즉, CPU코어의 사용을 조절한다. -1는 맥시멈 사용을 뜻한다

 

Step

from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error

model = LinearRegression(n_jobs=-1)
model.fit(x_train, y_train)
# -> LinearRegression(copy_X=True, fit_intercept=True, n_jobs=-1, normalize=False)
pred = model.predict(x_test)
mean_squred_error(pred, y_test)
# -> LinearRegression  25.129814