Skip to content

Instantly share code, notes, and snippets.

@patrickbrus
Last active January 10, 2021 18:30
Show Gist options
  • Save patrickbrus/5b4badfc3c3c8407da7025b8791c967b to your computer and use it in GitHub Desktop.
Save patrickbrus/5b4badfc3c3c8407da7025b8791c967b to your computer and use it in GitHub Desktop.
Fit a bayesian optimizer and a decsion tree model
# Define a model
tree = DecisionTreeRegressor(criterion="mse")
# Create the Bayesion optimization object
opt = BayesSearchCV(
tree,
{
"max_depth": (5, 15),
"splitter": ["best", "random"],
},
n_iter=n_iter,
cv=n_folds
)
# Train the model
opt.fit(train_x, train_y)
model = opt.best_estimator_
# Save the trained model
joblib.dump(model, os.path.join(args.model_dir, "model.joblib"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment