Skip to content

Instantly share code, notes, and snippets.

@gabriel19913
Last active November 30, 2019 12:04
Show Gist options
  • Save gabriel19913/28fc031660ebcebee23fed24b452b0f5 to your computer and use it in GitHub Desktop.
Save gabriel19913/28fc031660ebcebee23fed24b452b0f5 to your computer and use it in GitHub Desktop.
import xgboost as xgb
xgb_reg = xgb.XGBRegressor()
parameters = {'learning_rate': [0.0001, 0.001, 0.01, 0.1, 0.2, 0.3, 0.5, 0.9],
'n_estimators': [100, 200, 300, 400, 500],
'max_depth': [3,4,6],
'min_child_weight': [1, 2, 3]
}
grid_xgb = RandomizedSearchCV(xgb_reg, parameters, cv=5, n_jobs=-1)
grid_xgb = grid_xgb.fit(X_train, y_train)
xgb_reg = grid_xgb.best_estimator_
y_pred = xgb_reg.predict(X_test)
print("O {} calibrado tem um score de {:.4f} no conjunto de teste.".format(xgb_reg.__class__.__name__,
xgb_reg.score(X_test, y_test)))
print("Estes são os melhores parâmetros: {}".format(grid_xgb.best_params_))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment