시작하기무료로 시작하기

집값을 수동으로 예측하기

모형 계수를 사용하면 예측값을 직접 계산할 수 있어요. 실제로 예측할 때는 .predict()를 사용하는 것이 더 좋지만, 수동으로 계산해 보면 예측이 마법이 아니라 단순한 산술 연산임을 확인하는 데 도움이 됩니다.

사실, 단순 선형회귀에서는 예측값이 절편에 기울기와 설명변수의 곱을 더한 값입니다.

$$\text{response} = \text{intercept} + \text{slope} * \text{explanatory}$$

mdl_price_vs_convexplanatory_data가 준비되어 있어요.

이 연습은 강의의 일부입니다

Python에서 statsmodels로 살펴보는 회귀 소개

강의 보기

연습 안내

  • mdl_price_vs_conv의 계수/모수를 가져와 coeffs에 할당하세요.
  • 절편(첫 번째 원소)을 coeffs에서 가져와 intercept에 할당하세요.
  • 기울기(두 번째 원소)를 coeffs에서 가져와 slope에 할당하세요.
  • 공식을 사용해 price_twd_msq를 수동으로 예측하세요. 절편, 기울기, 그리고 explanatory_data를 지정하세요.
  • 코드를 실행해 수동으로 계산한 예측값을 .predict() 결과와 비교하세요.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

# Get the coefficients of mdl_price_vs_conv
coeffs = ____

# Get the intercept
intercept = ____

# Get the slope
slope = ____

# Manually calculate the predictions
price_twd_msq = ____
print(price_twd_msq)

# Compare to the results from .predict()
print(price_twd_msq.assign(predictions_auto=mdl_price_vs_conv.predict(explanatory_data)))
코드 편집 및 실행