Last active
November 15, 2020 12:46
-
-
Save vineethm1627/b2c77df970dc490c88707f3785e0ab8a 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
# Import necessary modules | |
from scipy.stats import randint | |
from sklearn.tree import DecisionTreeClassifier | |
from sklearn.model_selection import RandomizedSearchCV | |
# Setup the parameters and distributions to sample from: param_dist | |
param_dist = {"max_depth": [3, None], | |
"max_features": randint(1, 9), | |
"min_samples_leaf": randint(1, 9), | |
"criterion": ["gini", "entropy"]} | |
# Instantiate a Decision Tree classifier: tree | |
tree = DecisionTreeClassifier() | |
# Instantiate the RandomizedSearchCV object: tree_cv | |
tree_cv = RandomizedSearchCV(tree, param_distributions = param_dist, cv=5, n_iter = 5) | |
# Fit it to the data | |
tree_cv.fit(X, y) | |
# Print the tuned parameters and score | |
print("Tuned Decision Tree Parameters: {}".format(tree_cv.best_params_)) | |
print("Best score is {}".format(tree_cv.best_score_)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment