Question: 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
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
