본문 바로가기

카테고리 없음

[패스트캠퍼스 수강 후기] 데이터분석 인강 100% 환급 챌린지 38회차 미션

46. ch06. sklearn - 앙상블 - 06. 그라디언트 부스트(Gradient) - 49. ch06. sklearn - 앙상블 - 09. 스태킹(Stacking) 앙상블

46. ch06. sklearn - 앙상블 - 06. 그라디언트 부스트(Gradient)

from sklearn.ensemble import GradientBoostingRegressor, GradientBoostingClassifier

gbr = GradientBoostingRegressor(random_state=42)
gbr.fit(x_train, y_train)
gbr_pred = gbr.predict(x_test)
mse_eval('GradientBoost Ensemble', gbr_pred, y_test)



gbr = GradientBoostingRegressor(random_state=42, learning_rate=0.01)
gbr.fit(x_train, y_train)
gbr_pred = gbr.predict(x_test)
mse_eval('GradientBoost Ensemble (lr=0.01)', gbr_pred, y_test)



gbr = GradientBoostingRegressor(random_state=42, learning_rate=0.01, n_estimators=1000, subsample=0.8)
gbr.fit(x_train, y_train)
gbr_pred = gbr.predict(x_test)
mse_eval('GradientBoost Ensemble (lr=0.01, est=1000)', gbr_pred, y_test)


47. ch06. sklearn - 앙상블 - 07. XGBoost

from xgboost import XGBRegressor, XGBClassifier

xgb = XGBRegressor(random_state=42)
xgb.fit(x_train, y_train)
xgb_pred = xgb.predict(x_test)
mse_eval('XGBoost', xgb_pred, y_test)



튜닝
xgb = XGBRegressor(random_state=42, learning_rate=0.01, n_estimators=1000, subsample=0.8, max_feasures=0.8, max_depth=7)
xgb.fit(x_train, y_train)
xgb_pred = xgb.predict(x_test)
mse_eval('XGBoost w/ Tuning', xgb_pred, y_test)



48. ch06. sklearn - 앙상블 - 08. LightGBM

from lightgbm import LGBMRegressor, LGBMClassifier

lgbm = LGBMRegressor(random_state=42)
lgbm.fit(x_train, y_train)
lgbm_pred = lgbm.predict(x_test)
mse_eval('LGBM', lgbm_pred, y_test)


lgbm = LGBMRegressor(random_state=42, learning_rate=0.01, n_estimators=20000, colsample_bytree=0.8, subsample=0.8, max_depth=7)
lgbm.fit(x_train, y_train)
lgbm_pred = lgbm.predict(x_test)
mse_eval('LGBM w/ Tuning', lgbm_pred, y_test)




49. ch06. sklearn - 앙상블 - 09. 스태킹(Stacking) 앙상블

from sklearn.ensemble import StackingRegressor

stack_models = [
('elasticnet', poly_pipeline),
('randomforest', rfr),
('gbr', gbr),
('lgbm', lgbm),
]


stack_reg = StackingRegressor(stack_models, final_estimator=xgb, n_jobs=-1)


stack_reg.fit(x_train, y_train)
stack_pred = stack_reg.predict(x_test)
mse_eval('Stacking Ensemble', stack_pred, y_test)





패스트캠퍼스 데이터분석 강의 링크
bit.ly/3imy2uN