Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- max_allowed_depth = []
- test_accuracy = []
- train_accuracy = []
- for max_depth in range(1, 32):
- dt_classifier = tree.DecisionTreeClassifier(max_depth=max_depth, random_state=my_seed)
- dt_classifier.fit(X_train, Y_train)
- Yhat = dt_classifier.predict(X_test)
- accuracy_train = dt_classifier.score(X_train, Y_train)
- accuracy_test = dt_classifier.score(X_test, Y_test)
- max_allowed_depth.append( max_depth )
- test_accuracy.append( accuracy_test )
- train_accuracy.append( accuracy_train )
- print(max_depth, accuracy_test)
- plt.title('Accuracy vs Max_allowed_depth')
- plt.plot(max_allowed_depth, test_accuracy, label='test_accuracy')
- plt.plot(max_allowed_depth, train_accuracy, label='train_accuracy')
- plt.xlabel = 'max_allowed_depth'
- plt.ylbabel = 'test_accuracy'
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement