Last active
March 30, 2016 21:05
-
-
Save monspo1/85170fc26448901c0f0569d2ef8ffc27 to your computer and use it in GitHub Desktop.
This file contains 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
import sklearn.grid_search as gs | |
# Fit a random forest on the training set. | |
from sklearn import ensemble | |
rf = ensemble.RandomForestClassifier() | |
rf.fit(x_train, y_train) # fit | |
#print "- The training error is: %.5f" %(1-rf.score(x_train, y_train)) | |
#print "- The test error is: %.5f" %(1-rf.score(x_test, y_test)) | |
# Find the best parameters using grid_search.GridSearchCV to | |
# The initial combination of the parameters: | |
# grid_para_forest = {'criterion': ['gini', 'entropy'], 'max_depth': range(1, 31), "n_estimators": range(10, 110, 10)} | |
grid_para_forest = [{'criterion': ['gini', 'entropy'], 'max_depth': range(1, 31), "n_estimators": range(10, 110, 10)}] | |
grid_search_forest = gs.GridSearchCV(rf, grid_para_forest, scoring='accuracy', cv=5) | |
grid_search_forest.fit(x_train, y_train) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment