Kaggle Machine Learning: Random Forests


Introduction


OverfittingとUnderfittingを解決する考えがたくさんあります.
この章では、Decision Treeを使用してモデルのパフォーマンスを向上させるランダムForestについて説明します.

Random Forest


  • パフォーマンスは、単一の決定ツリーモデルよりも優れています.

  • default parametersもうまく機能します.
  • Example

    DecisionTreeRegressorではなく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_predis = forest_model.predict(val_X)
    print(mean_absolute_error(val_y, melb_preds))

    Conclusion


    Single Decision Treeでは、パフォーマンスが最も優れているリーフノードの数を見つけ、数を指定しました.
    ただし、Random forestの場合はパラメータを指定できますが、通常は指定されていなくてもうまく動作します.

    Exercise


    Step 1: Use a Random Forest

    from sklearn.ensemble import RandomForestRegressor
    
    rf_model = RandomForestRegressor(random_state=1)
    
    rf_model.fit(train_X, train_y)
    
    rf_val_pred = rf_model.predict(val_X)
    rf_val_mae = mean_absolute_error(rf_val_pred, val_y)