Skip to content

Instantly share code, notes, and snippets.

@finnqiao
Created January 8, 2019 17:38
Show Gist options
  • Save finnqiao/1300e2846a0e1b57256a275cd35e5811 to your computer and use it in GitHub Desktop.
Save finnqiao/1300e2846a0e1b57256a275cd35e5811 to your computer and use it in GitHub Desktop.
# Create first pipeline for base without reducing features.
pipe = Pipeline([('classifier' , RandomForestClassifier())])
# pipe = Pipeline([('classifier', RandomForestClassifier())])
# Create param grid.
param_grid = [
{'classifier' : [LogisticRegression()],
'classifier__penalty' : ['l1', 'l2'],
'classifier__C' : np.logspace(-4, 4, 20),
'classifier__solver' : ['liblinear']},
{'classifier' : [RandomForestClassifier()],
'classifier__n_estimators' : list(range(10,101,10)),
'classifier__max_features' : list(range(6,32,5))}
]
# Create grid search object
clf = GridSearchCV(pipe, param_grid = param_grid, cv = 5, verbose=True, n_jobs=-1)
# Fit on data
best_clf = clf.fit(X_train, y_train)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment