1 개요
데이터 분석과 관련한 기능.
2 선형 회귀분석
2.1 회귀선 그리기
from sklearn.linear_model import LinearRegression
x = # x축 데이터
y = # y축 데데이터
model = LinearRegression()
model.fit(x, y)
y_pred = pd.Series(model.predict(x), index=x.index) # 회귀선을 얻을 수 있다.
2.1.1 여러 데이터를 사용하는 경우(다중 선형 회귀분석)
from sklearn.linear_model import LinearRegression
x = df[['변수1', '변수2', '변수3', ...]] # x축 데이터
y = df[['결과']] # y축 데데이터
model = LinearRegression()
model.fit(x, y)
y_pred = pd.Series(model.predict(x), index=x.index) # 회귀선을 얻을 수 있다.
print("변수에 대한 예상값 : ",model.predict([['임의값1', '임의값2', '임의값3', ...]]))
2.2 회귀 결과
의도 | 설명 | 방법 |
---|---|---|
절편값 구하기 | 모든 변수가 0일 때의 y값 | model.intercept_ |
회귀계수 구하기 | 기울기의 역할. | model.coef_ |