Last active
September 26, 2018 13:45
-
-
Save emmagrimaldi/6f3d46d0020d588763d8b9c8d4506005 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from sklearn.ensemble import RandomForestClassifier | |
| from sklearn.pipeline import Pipeline | |
| steps = [ | |
| ("vectorizer", TfidfVectorizer(stop_words=my_stopwords)), | |
| ("rf", RandomForestClassifier()) | |
| ] | |
| # instatiating the pipeline | |
| pipe = Pipeline(steps) | |
| # setting the values for the RandomForest model | |
| grid_params = { | |
| "vectorizer__max_features": [2000, 3000, 4000], | |
| "vectorizer__ngram_range":[(1,1), (1,2)], | |
| "rf__n_estimators": [2500, 3000, 3500], | |
| "rf__max_depth": [17, 18, 19, 20], | |
| "rf__min_samples_leaf": [1, 2, 3] | |
| } | |
| # grid search | |
| gs = GridSearchCV(pipe, grid_params, verbose=1, n_jobs=2) | |
| results = gs.fit(X_train, y_train) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment