Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python Decision Tree implementation help I can only import numpy, and must do the rest using built-in functions. There are other ones such as KNN

Python Decision Tree implementation help

image text in transcribed

image text in transcribed

I can only import numpy, and must do the rest using built-in functions. There are other ones such as KNN and Clustering which weren't a problem, but I'm just getting super confused with the decision tree section. Help with any of the 3 functions would be appreciated

Implement a function in python: DT train binary (X, Y,max_depth) that takes training data as input. The labels and the features are binary, but the feature vectors can be of any finite dimension. The training feature data (X) should be structured as a 2D numpy array, with each row corresponding to a single sample. The training labels (Y) should be structured as a 1D numpy array, with each row corresponding to a single label. X and Y should have the same number of rows, with each row corresponding to a single sample and its label. max.depth is an integer that indicates the maximum depth for the resulting decision tree. DT_train binary (X, Y,max depth) should return the decision tree that achieves the best accuracy on the training data, limited by some given maximum depth. If max depth is set to -1 then DT train binary (X, Y,max depth) should return a decision tree that achieves the maximum accuracy on the training data (i.e. any depth). You may store a decision tree however you would like, i.e. a list of lists, a class, a dictionary, etc. Write-Up: describe your implementation in detail. Implement a function in python: DT test_binary (X, Y,DT) that takes test data X and test labels Y and a learned decision tree model DT, and returns the accuracy on the test data using the decision tree for predictions. Write-Up: describe your implementation in detail Grading: I will use a script similar to the following to test your code. Note that I l test many different scenarios, so your functions should be able to handle any set of binary features, binary labels, and maximum depth import numpy as np Y = np . array ([[1] ,[1] ,1011) max depth2 DT DT train binary (X, Y, max.depth) test.accDT test.binary (X, Y,DT) Implement a function in python DT train binary_best (X_train, Y train, X_val, Y val) This function should use DTtestbinary (X, Y,DT) to test the current decision tree at each step using the validation data (Xval,Y val). Return the decision tree that achieves the best accuracy on the validation data. Write-Up: describe your implementation in detail. Implement a function in python: DT train binary (X, Y,max_depth) that takes training data as input. The labels and the features are binary, but the feature vectors can be of any finite dimension. The training feature data (X) should be structured as a 2D numpy array, with each row corresponding to a single sample. The training labels (Y) should be structured as a 1D numpy array, with each row corresponding to a single label. X and Y should have the same number of rows, with each row corresponding to a single sample and its label. max.depth is an integer that indicates the maximum depth for the resulting decision tree. DT_train binary (X, Y,max depth) should return the decision tree that achieves the best accuracy on the training data, limited by some given maximum depth. If max depth is set to -1 then DT train binary (X, Y,max depth) should return a decision tree that achieves the maximum accuracy on the training data (i.e. any depth). You may store a decision tree however you would like, i.e. a list of lists, a class, a dictionary, etc. Write-Up: describe your implementation in detail. Implement a function in python: DT test_binary (X, Y,DT) that takes test data X and test labels Y and a learned decision tree model DT, and returns the accuracy on the test data using the decision tree for predictions. Write-Up: describe your implementation in detail Grading: I will use a script similar to the following to test your code. Note that I l test many different scenarios, so your functions should be able to handle any set of binary features, binary labels, and maximum depth import numpy as np Y = np . array ([[1] ,[1] ,1011) max depth2 DT DT train binary (X, Y, max.depth) test.accDT test.binary (X, Y,DT) Implement a function in python DT train binary_best (X_train, Y train, X_val, Y val) This function should use DTtestbinary (X, Y,DT) to test the current decision tree at each step using the validation data (Xval,Y val). Return the decision tree that achieves the best accuracy on the validation data. Write-Up: describe your implementation in detail

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

Data Management Databases And Organizations

Authors: Richard T. Watson

2nd Edition

0471180742, 978-0471180746

More Books

Students also viewed these Databases questions

Question

What is meant by a firms positioning strategy?

Answered: 1 week ago

Question

Find the derivative of y= cos cos (x + 2x)

Answered: 1 week ago