Question
Hi, I need help for the below question, the answer for the below question was I got it in Chegg here. After submission for the
Hi, I need help for the below question, the answer for the below question was I got it in Chegg here. After submission for the code, I received an error. Please help me on the coding. Thank you so much.
Question and Answer submission:
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=None) 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)
The error after submission:
AssertionError Traceback (most recent call last)in Traceback Redacted AssertionError: Look at Problem 2, part B. Did you build and fit a DecisionTreeClassifier using sklearn?
Please help me the code. Thank you so much.
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