Skip to content

Instantly share code, notes, and snippets.

@marcosatanaka
Last active April 29, 2018 03:16
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 marcosatanaka/f67879deac6300228c623ea789a1eb59 to your computer and use it in GitHub Desktop.
Save marcosatanaka/f67879deac6300228c623ea789a1eb59 to your computer and use it in GitHub Desktop.
def fit_model(X, y):
# Gera conjuntos de validação-cruzada para o treinamento de dados
cv_sets = ShuffleSplit(X.shape[0] # qt total elementos
, n_iter = 10 # qt vezes embaralhar e dividir
, test_size = 0.2
, random_state = 123)
grid = GridSearchCV(DecisionTreeRegressor()
, dict(max_depth = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
, make_scorer(performance_metric)
, cv = cv_sets)
# Encontrando os melhores parâmetros do estimador
grid = grid.fit(X, y)
return grid.best_estimator_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment