Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, I have the problem with the same question. At first, I got the answer from Chegg here. After my two times submission I still

Hi, I have the problem with the same question. At first, I got the answer from Chegg here. After my two times submission I still got the same error.

Please take note on the DECISIONTREE CLASSIFIER MAX_DEPTH PART. I have change the max_depth=None(first time submission) to max_depth=2(second time submission), but still got the same error. Please help me on the coding. Thank you.

Question and the answer:

Part B[5 points] : Build a decision tree classifier using the sklearn toolbox. Then compute metrics for performance like precision and recall. This is a binary classification problem, therefore we can label all points as either positive (SPAM) or negative (NOT SPAM).

def build_dt(data_X, data_y, max_depth = None, max_leaf_nodes =None): ''' This function builds the decision tree classifier and fits it to the provided data. Arguments data_X - a np.ndarray data_y - np.ndarray max_depth - None if unrestricted, otherwise an integer for the maximum depth the tree can reach. Returns: A trained DecisionTreeClassifier ''' # your code here from sklearn.tree import DecisionTreeClassifier from sklearn.metrics import precision_recall_fscore_support clf = DecisionTreeClassifier(max_depth=2) clf.fit(data_X, data_y) # Get the metrics precision, recall, fscore, support = precision_recall_fscore_support(data_y, clf.predict(data_X)) # Print the results print("Precision:", precision) print("Recall:", recall) print("F-score:", fscore) print("Support:", support) return clf

The Error after 2 times submission:

AssertionError Traceback (most recent call last)  in  Traceback Redacted AssertionError: Look at Problem 2, part B. Is your decision tree the proper depth?

Please help me on the coding. Thank you so much.

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2022 Grenoble France September 19 23 2022 Proceedings Part 4 Lnai 13716

Authors: Massih-Reza Amini ,Stephane Canu ,Asja Fischer ,Tias Guns ,Petra Kralj Novak ,Grigorios Tsoumakas

1st Edition

3031264118, 978-3031264115

More Books

Students also viewed these Databases questions

Question

1. Describe the factors that lead to productive conflict

Answered: 1 week ago