decision_tree_classifier_visualization

py

School

University of Central Florida *

*We aren’t endorsed by this school

Course

5610

Subject

Computer Science

Date

Apr 3, 2024

Type

py

Pages

2

Uploaded by madhu_iitm

Report
# -*- coding: utf-8 -*- """Decision Tree Classifier Visualization.ipynb Automatically generated by Colaboratory. Original file is located at ## Imports """ import pickle """## Upload the saved model files! ``` RFModel.pick and RFModel_max_depth_3.pick ``` ## Load saved models """ # Each trained model was saved with this pickle command: #pickle.dump(<model_name>, open(<saved_model_file_name>, "wb" ) ) RFModel = pickle.load(open("RFModel.pick", "rb")) # This model was created with a max_depth=3 hyperparameter to facilitate visualization RFModel_stumped = pickle.load(open("RFModel_max_depth_3.pick", "rb")) RFModel.get_params()['max_depth'] # None is not printed RFModel_stumped.get_params()['max_depth'] """## Model visualization""" # The loaded Random Forest model has 100 estimators RFModel.get_params()['n_estimators'] # Each estiamator is a weak learner of type DecisionTreeClassifier RFModel.estimators_ [:3] # Commented out IPython magic to ensure Python compatibility. # %matplotlib inline import matplotlib.pyplot as plt from sklearn import tree def plot_tree(tree_model): plt.figure(figsize=(14,14)) tree.plot_tree(tree_model, class_names= ['Non-Spam', 'Spam']); # Looking at the BIG picture first # Plotting may take up to 20 seconds or more -- be patient! plot_tree(RFModel.estimators_[0]) # You should see quite a tall tree (shown upside down) # Now plot a small tree represented by the first (out of 100) estimators of the
smaller model plot_tree(RFModel_stumped.estimators_[0]) """*End of the lab notebook*"""
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help