Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In Python: 1 . Set predictors and outcome variables, and partition the data into 6 0 % training, 4 0 % validation # 1 #Set
In Python: Set predictors and outcome variables, and partition the data into training, validation
#
#Set predictors and outcome
predictors Cleanliness 'Nurse communication, 'Doctor Communication', 'Discharge information', 'MetColor', 'Automatic', CC 'Doors', 'Tax', 'Weight'
outcome 'Rating'
# Train a tree for classification
# Run random forest and boosted tree models for classification
# Which rf variable is the most important? eg importances rfmodel.namedstepsclassifierfeatureimportances
# Assess the performance of all models using Sklearn classificationreport. Which model is better? See an example below
#of how to set up one of the models
# classTree DecisionTreeClassifierrandomstate maxdepth minsamplessplit
# treemodel Pipelinesteps
# preprocessor preprocessor
# classifier classTree
#
# treemodel.fittrainX trainy
# predy treemodel.predictvalidX
# printDecisionTreeClassifier Classification Report
# printclassificationreportvalidy predy
# Visualize the tree. See an example below
# fittedtree treemodel.namedstepsclassifier
# classnames strcls for cls in fittedtree.classes
# transformedfeaturenames treemodel.namedstepspreprocessorgetfeaturenamesout
# dotdata exportgraphvizfittedtree, outfileNone,
# featurenamestransformedfeaturenames,
# classnamesclassnames,
# filledTrue, roundedTrue,
# specialcharactersTrue
# graph graphviz.Sourcedotdata
# graph.renderDecisionTree", formatpng
# graph.view
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started