Skip to content

Instantly share code, notes, and snippets.

@JonathanLoscalzo
Created February 17, 2020 15:10
Show Gist options
  • Select an option

  • Save JonathanLoscalzo/71a620a9f71547ba4ef05b32e841f3c7 to your computer and use it in GitHub Desktop.

Select an option

Save JonathanLoscalzo/71a620a9f71547ba4ef05b32e841f3c7 to your computer and use it in GitHub Desktop.
gridsearch_example for post
params_rf = {
'clf__n_estimators':[
100,
300,
500
],
'clf__min_samples_leaf': [
1,
2,
4
],
'clf__min_samples_split': [
2,
5,
10
],
'clf__max_features': [
'auto',
'sqrt'
],
'clf__bootstrap': [
True,
False
],
'clf__class_weight':[
'balanced',
'balanced_subsample',
None,
utils.compute_weights(y)
]
}
params_fit_rf = {
}
gs_rf = GridSearchCV(
estimator=get_pipeline_model(RandomForestClassifier()),
param_grid = params_rf,
verbose=10,
scoring= {
'accuracy': make_scorer(accuracy_score),
'f1_score': make_scorer(f1_score, average='weighted'),
},
cv=StratifiedKFold(3),
return_train_score=True,
refit='accuracy',
n_jobs=-1
)
gs_rf = gs_rf.fit(X_train, y_train)
def compute_weights(y):
weights = compute_class_weight("balanced", np.unique(y), y)
return { i:k for i,k in enumerate(weights)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment