Skip to content

Instantly share code, notes, and snippets.

@harrywang
Created May 13, 2021 21:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harrywang/afd9f7fc714ac992dad139d69161f701 to your computer and use it in GitHub Desktop.
Save harrywang/afd9f7fc714ac992dad139d69161f701 to your computer and use it in GitHub Desktop.
ensemble learning hints
# partial code snippets shown as hints
# voting regressor
from sklearn.ensemble import VotingRegressor
voting_reg = VotingRegressor(
estimators = [
('lin', lin_reg_pipeline),
('svm', svm_reg_pipeline),
('sgd', sgd_reg_pipeline),
],
)
# random forest regressor and tuning parameters
from sklearn.ensemble import RandomForestRegressor
rf_pipeline = Pipeline(
steps=[
('preprocessor', preprocessor),
('rf', RandomForestRegressor()),
]
)
param_grid = [
{
'rf__n_estimators': [50, 100, 200, 300],
'rf__max_depth': [2, 3, 5, 10, 20],
}
]
# GBRT example
from sklearn.ensemble import GradientBoostingRegressor
gb_pipeline = Pipeline(
steps=[
('preprocessor', preprocessor),
('gb', GradientBoostingRegressor()),
]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment