Tree Classifier Focus on Best Parameters with GridSearchCV

Importing Modules


In [ ]:
from sklearn import tree
from sklearn.model_selection import GridSearchCV

Run Variables Setup If Necessary


In [ ]:
if 'features_train' or 'features_train_small' not in locals() or globals():
    %run ../dev/environment_setup2.ipynb

Decision Tree Classifier and GridSeach Load


In [ ]:
parameters = {"criterion": ["gini", "entropy"],
              "min_samples_split": [2, 10, 20],
              "max_depth": [None, 2, 5, 10],
              "min_samples_leaf": [1, 5, 10],
              "max_leaf_nodes": [None, 5, 10, 20],
              }
svr = tree.DecisionTreeClassifier()
clf = GridSearchCV(svr, parameters)

Train and Predict


In [ ]:
grid_train_predict("Decision Tree with GridSearchCV and Reduced Dataset...")
sorted(clf.cv_results_.keys())
param = "Best Param: " +  str(clf.best_params_)
print (param)
score = "Best Avarage Score: " + str(clf.best_score_)
print (score)