Answered step by step
Verified Expert Solution
Link Copied!

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: 1. Set predictors and outcome variables, and partition the data into 60% training, 40% validation
#1
#Set predictors and outcome
predictors =['Cleanliness', 'Nurse communication, 'Doctor Communication', 'Discharge information', 'Met_Color', 'Automatic', 'CC', 'Doors', 'Tax', 'Weight']
outcome = 'Rating'
# 2. Train a tree for classification
# 3. Run random forest and boosted tree models for classification
# 4. Which rf variable is the most important? (e.g., importances = rf_model.named_steps['classifier'].feature_importances_)
# 5. Assess the performance of all models using Sklearn classification_report. Which model is better? See an example below
#of how to set up one of the models
# classTree = DecisionTreeClassifier(random_state=0, max_depth =5, min_samples_split =50)
# tree_model = Pipeline(steps=[
# ('preprocessor', preprocessor),
# ('classifier', classTree)
# ])
# tree_model.fit(train_X, train_y)
# pred_y = tree_model.predict(valid_X)
# print('--------------DecisionTreeClassifier Classification Report--------------------')
# print(classification_report(valid_y, pred_y))
# 6. Visualize the tree. See an example below
# fitted_tree = tree_model.named_steps['classifier']
# class_names =[str(cls) for cls in fitted_tree.classes_]
# transformed_feature_names = tree_model.named_steps['preprocessor'].get_feature_names_out()
# dot_data = export_graphviz(fitted_tree, out_file=None,
# feature_names=transformed_feature_names,
# class_names=class_names,
# filled=True, rounded=True,
# special_characters=True)
# graph = graphviz.Source(dot_data)
# graph.render("Decision_Tree", format="png"
# graph.view()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Define Decision making

Answered: 1 week ago

Question

What are the major social responsibilities of business managers ?

Answered: 1 week ago

Question

What are the skills of management ?

Answered: 1 week ago