파이프라인에서의 전처리
Ames 주택 데이터에 대해 개별적으로 어떤 전처리 단계를 거쳐야 하는지 살펴봤으니, 이제 더 깔끔하고 간결한 DictVectorizer 방식을 사용해 보겠습니다. 이를 XGBoostRegressor와 함께 scikit-learn 파이프라인에 넣어 구성해 볼게요.
이 연습은 강의의 일부입니다
XGBoost로 익히는 Extreme Gradient Boosting
연습 안내
sklearn.feature_extraction에서DictVectorizer,sklearn.pipeline에서Pipeline을 임포트하세요.X의LotFrontage열에 있는 결측값을0으로 채우세요.- 파이프라인의 스텝을 완성하세요.
"ohe_onestep"에는DictVectorizer(sparse=False),"xgb_model"에는xgb.XGBRegressor()를 사용합니다. Pipeline()과steps를 사용해 파이프라인을 생성하세요.Pipeline을 학습(fit)하세요. 이때DictVectorizer가 이해하는 형식으로 변환하기 위해X에to_dict("records")메서드를 호출하는 것을 잊지 마세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Import necessary modules
____
____
# Fill LotFrontage missing values with 0
X.LotFrontage = ____
# Setup the pipeline steps: steps
steps = [("ohe_onestep", ____),
("xgb_model", ____)]
# Create the pipeline: xgb_pipeline
xgb_pipeline = ____
# Fit the pipeline
____