ML,DL

Random Forests

BKM 2021. 9. 3. 09:57

참고 : https://www.kaggle.com/nickneim/exercise-random-forests/edit

참고 : https://sdsf1225.tistory.com/25

  • Decision-Tree에서는 Underfitting과 Overfitting의 문제 사이에서 Sweet-spot을 찾는 것이 문제점이라고 다뤘었다
  • Random Forests기법은 Decision-Tree의 이러한 문제점을 보완하기 위해서 1개의 Tree가 아니라 여러개의 'Trees'를 사용해서 각 Tree의 평균을 구해서 예측에 활용한다

간단한 Random Forest 구현

from sklearn.ensemble import RandomForestRegressor
from sklearn.metrics import mean_absolute_error

forest_model = RandomForestRegressor(random_state=1)
forest_model.fit(train_X, train_y)
melb_preds = forest_model.predict(val_X)
print(mean_absolute_error(val_y, melb_preds))
# Output

191669.7536453626

지난 Decision-Tree기법에서의 MAE에 비해 월등히 낮아졌음을 확인할 수 있다.