Question: Similarly, write the function `train_tree_eval_acc` that trains Decision Forest models and takes following the arguments: * `train_images`: A numpy array with the shape `(N,height,width)`, where
Similarly, write the function `train_tree_eval_acc` that trains Decision Forest models and takes following the arguments: * `train_images`: A numpy array with the shape `(N,height,width)`, where * `N` is the number of samples and could be anything, * `height` is each individual image's height in pixels (i.e., number of rows in each image), * and `width` is each individual image's width in pixels (i.e., number of columns in each image). Do not assume anything about `images`'s dtype or number of samples. * `train_labels`: A numpy array with the shape `(N,)`, where `N` is the number of samples and has the `int64` dtype. * `eval_images`: The evaluation images with similar characteristics to `train_images`. * `eval_labels`: The evaluation labels with similar characteristics to `eval_labels`. * `tree_num`: An integer number representing the number of trees in the dicision forest. * `tree_depth`: An integer number representing the maximum tree depth in the dicision forest. * `random_state`: An integer with a default value of 12345 that should be passed to the scikit-learn's classifer constructor for reproducibility and auto-grading (**Do not assume** that it is always 12345). and returns the following: * `eval_acc`: A floating number scalar between 0 and 1 that represents the accuracy of the trained model on the evaluation data. We have provided a template function that uses the previous functions and only requires you to fill in the missing parts. It also handles the input shapes in an agnostic way. **Note**: You do not need to implement the Random Forest classifier from scratch in this assignment; Make sure you use `scikit-learn`'s Random Forest module for training and prediction in this task. We have already imported this function in the first code cell: * `from sklearn.ensemble import RandomForestClassifier` * You may need to set "shuffle = True" due to a known sklearn issue.
SUBMIT TEXT, NOT A SCREENSHOT. IT MUST PASS THE ASSERTION CHECK
def train_tree_eval_acc(train_images, train_labels, eval_images, eval_labels, tree_num=10, tree_depth=4, random_state=12345): """ Trains Naive Bayes models, apply the model, and return an accuracy.
Parameters: train_images (np.array): A numpy array with the shape (N,height,width) train_labels (np.array): A numpy array with the shape (N,), where N is the number of samples and has the int64 dtype. eval_images (np.array): The evaluation images with similar characteristics to train_images. eval_labels (np.array): The evaluation labels with similar characteristics to train_labels. tree_num (int): An integer number representing the number of trees in the decision forest. tree_depth (int): An integer number representing the maximum tree depth in the decision forest. random_state (int): An integer with a default value of 12345 that should be passed to the scikit-learn's classifer constructor for reproducibility and auto-grading Returns: eval_acc (np.float): a floating number scalar between 0 and 1 that represents the accuracy of the trained model on the evaluation data. """ tree_num = int(tree_num) tree_depth = int(tree_depth) random_state = int(random_state) # YOUR CODE HERE raise NotImplementedError return eval_acc
-------------------------------------------------------------------------------
#ASSERTION:
# Checking against the pre-computed test database test_results = test_case_checker(train_tree_eval_acc, task_id=9) assert test_results['passed'], test_results['message']
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
