예측을 수동으로 계산하기
단순 선형 회귀와 마찬가지로, 모형 계수로부터 예측값을 수동으로 계산할 수도 있어요. 평행 기울기(Parallel Slopes) 모형의 차이점은, 범주형 설명 변수의 각 범주마다 절편이 다르다는 점이에요. 즉, 각 범주가 나타나는 경우를 각각 따로 고려해야 해요.
taiwan_real_estate, mdl_price_vs_both, explanatory_data가 준비되어 있고, 이전 연습 문제에서 구한 ic_0_15, ic_15_30, ic_30_45, slope도 로드되어 있어요.
이 연습은 강의의 일부입니다
Python의 statsmodels로 배우는 중급 회귀
연습 안내
conditions리스트를 정의하세요. 조건문은 세 가지로,house_age_years가"0 to 15",house_age_years가"15 to 30",house_age_years가"30 to 45"인 경우예요.choices리스트를 정의하세요.mdl_price_vs_both에서 추출한 절편들을 담고, 각 조건과 순서가 대응되도록 하세요.np.select()를 사용해 절편의 배열을 생성하세요.prediction_data를 만드세요.explanatory_data로 시작해intercept에 위에서 만든 절편 배열을 할당하고,price_twd_msq에는 수동으로 계산한 예측값을 할당하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Define conditions
conditions = [____]
# Define choices
choices = [____]
# Create array of intercepts for each house_age_year category
intercept = ____(____, ____)
# Create prediction_data with columns intercept and price_twd_msq
prediction_data = ____.____(
____ = ____,
____ = ____ + ____ * ____[____])
print(prediction_data)