|
|
|
Problem 1: Decision Trees for Spam Classification We’ll use the same data as in our earlier homework: In order to reduce my email load, I decide to implement a machine learning algorithm to decide whether or not I should read an email, or simply file it away instead. To train my model, I obtain the following data set of binary-valued features about each email, including whether I know the author or not, whether the email is long or short, and whether it has any of several key words, along with my final decision about whether to read it ( y = +1 for “read”, y = −1 for “discard”). x1 x2 x3 x4 x5 y know author? is long? has ‘research’ has ‘grade’ has ‘lottery’ ⇒ read? 0 0 1 1 0 -1 1 1 0 1 0 -1 0 1 1 1 1 -1 1 1 1 1 0 -1 0 1 0 0 0 -1 101111 001001 100001 101101 1 1 1 1 1 -1 In the case of any ties where both classes have equal probability, we will prefer to predict class +1.
Problem 2: Decision Trees in Python In this problem, we will use our Kaggle in-class competition data to test decision trees on real data. Kaggle is a website designed to host data prediction competitions; we will use it to gain some experience with more realistic machine learning problems, and have an opportunity to compare methods and ideas amongst ourselves. Our in-class Kaggle page is https://www.kaggle.com/c/uci-cs178-f20; you can join using the participation URL: https://www.kaggle.com/t/bd21e4e5d61540888ed61f438bac55b8 Follow the instructions on the CS178 Canvas page to create an appropriate Kaggle account (if necessary), join our in-class competition, and download the competition data. Note: although you will eventually form teams for the project, please do not merge yet, as you will want to be able to submit individually for this homework. For convenience, the data are also included in the HW4 code zip, in the data subdirectory. 1. The following code may be used to load the training features X and class labels Y : |
|
|
1 2 3 4 1 X = X[:,:41] # keep only the numeric features for now 2. To enable us to do model selection, partition your training data X into training data Xtr,Ytr and validation sets Xva,Yva of approximately equal size. Learn a decision tree classifier from the training data using the method implemented in the mltools package (this may take a minute): 1 learner = ml.dtree.treeClassify(Xtr, Ytr, maxDepth=50) Here, we set the maximum tree depth to 50 to avoid potential recursion limits or memory issues. Compute and report your decision tree’s training and validation error rates. (5 points) The first 41 features are numeric (real-valued features); we will restrict our attention to these: 3. Now try varying the many levels. Test error rates versus choice of parameter, which forces the tree learning algorithm to stop after at most that values in the range , and plot the training and validation . Do models with higher have higher or lower complexity? What provides the best decision tree model? (10 points) maxDepth maxDepth maxDepth 0, 1, 2, ..., 15 maxDepth maxDepth
1 2 3 4 5 Note that we use predictSoft to output probabilistic predictions (that test examples are members of class 1) for upload to Kaggle. While you may also use “hard” predictions (class values), accounting for the learned model’s confidence in each prediction will produce a smoother ROC curve and (usually) a better AUC score. maxDepth=50 2.∧[0:13]=[1,2,4,8,…,8192]
Submit your predictions on all of the test data to Kaggle, and include your Kaggle username and leaderboard AUC in your homework solutions. (10 points) |
||||
|
|
|
|
|
1 2 3 Problem 3: Ensemble Methods Choose either part of this question to answer (your choice): a random forest classifier, which is a bagged ensemble of decision trees; or an boosted ensemble of regression trees learned with gradient boosting. In Python, it is easy to keep a list of different learners, even of different types, for use in an ensemble predictor: Option 1: Random forests: Random Forests are bagged collections of decision trees, which select their decision nodes from randomly chosen subsets of the possible features (rather than all features). You can implement this easily in treeClassify using option ’nFeatures’ =n, where n is the number of features to select from (e.g., n = 50 or n = 60 if there are 90-some features); you’ll write a for-loop to build the ensemble members, and another to compute the prediction of the ensemble.
Option 2: Gradient boosting: Gradient boosted trees are boosted collections of decision trees, which are build sequentially to predict the residual error in the current ensemble. You’ll write a for-loop to build the ensemble members, and another to compute the prediction of the ensemble. Since this is a classification problem, we will do gradient boosting on a logistic negative log likelihood loss, i.e., we will regress the log-odds ratio in a manner similar to logistic regression (except that, instead of a linear regression on the log-odds, we will use a collection of decision trees). Use to fit each learner to the (real-valued) log-odds update; treeRegress works analagously to . In practice, start out with a baseline predictor f (x) = 0, and compute probabilies p(y = 1) = σ(f (x)) where σ is the usual logistic function. Then, update f (x) by regressing the derivative of J: dJ(i) 1−σ(f(x(i))) y(i) =1 df(i) = −σ(f(x(i))) y(i) =0 Fit dJ using a regression tree t(x), and update f (x) = f (x) + αt(x) for some step size α.
ensemble[i] = ml.treeClassify(Xb,Yb,…) # save ensemble member “i” in a cell array treeRegress treeClassify |
|
|
|
|
|
Problem 4: Statement of Collaboration It is mandatory to include a Statement of Collaboration in each submission, that follows the guidelines below. Include the names of everyone involved in the discussions (especially in-person ones), and what was discussed. All students are required to follow the academic honesty guidelines posted on the course website. For programming assignments in particular, I encourage students to organize (perhaps using Piazza) to discuss the task descriptions, requirements, possible bugs in the support code, and the relevant technical content before they start working on it. However, you should not discuss the specific solutions, and as a guiding principle, you are not allowed to take anything written or drawn away from these discussions (no photographs of the blackboard, written notes, referring to Piazza, etc.). Especially after you have started working on the assignment, try to restrict the discussion to Piazza as much as possible, so that there is no doubt as to the extent of your collaboration. |
|
Homework 4 UC Irvine 4/ 4 |



