Description
Submission: You need to submit three files through MarkUs :
• Your answers to Questions 1, 2, and 3, and outputs requested for Question 2, as a PDF file titled hw1_writeup.pdf. You can produce the file however you like (e.g. LATEX, Microsoft Word, scanner), as long as it is readable.
• Your code for Question 2, as the Python file hw1_code.py. This should contain the functions load_data, select_model, and compute_information_gain.
Neatness Point: One point will be given for neatness. You will receive this point as long as we don’t have a hard time reading your solutions or understanding the structure of your code.
Late Submission: 10% of the marks will be deducted for each day late, up to a maximum of 3 days. After that, no submissions will be accepted.
Computing: To install Python and required libraries, see the instructions on the course web page. Homeworks are individual work. See the Course Information handout for detailed policies.
Basic rule of expectation and variance: E[Zi+Zj] = E[Zi]+E[Zj] and if we further know Zi and Zj are independent, then Var[Zi + Zj] = Var[Zi] + Var[Zj].
(c) [Optional, 0pts] In probability theory, one can derive that for any random variable Z. (This fact is known as Markov’s Inequality.) Based on your answer to part (b), explain why does this support the claim that in high dimensions, “most points are far away, and approximately the same distance”?
2. [8pts] Decision Trees. This question is taken from a project by Lisa Zhang and Michael Guerzhoy.
In this question, you will use the scikit-learn decision tree classifier to classify real vs. fake news headlines. The aim of this question is for you to read the scikit-learn API and get comfortable with training/validation splits.
Each headline appears as a single line in the data file. Words in the headline are separated by spaces, so just use str.split() in Python to split the headlines into words.
You will build a decision tree to classify real vs. fake news headlines. Instead of coding the decision trees yourself, you will do what we normally do in practice — use an existing implementation. You should use the DecisionTreeClassifier included in sklearn. Note that figuring out how to use this implementation is a part of the assignment.
Here’s a link to the documentation of sklearn.tree.DecisionTreeClassifier: http:// scikit-learn.org/stable/modules/generated/sklearn.tree.DecisionTreeClassifier. html
All code should be included in the file hw1_code.py which you submit through MarkUs.
(a) [2pt] Write a function load_data which loads the data, preprocesses it using a vectorizer
(http://scikit-learn.org/stable/modules/classes.html#module-sklearn.feature_ extraction.text), and splits the entire dataset randomly into 70% training, 15% validation, and 15% test examples.
(b) [2pt] Write a function select_model which trains the decision tree classifier using at least 5 different values of max_depth, as well as two different split criteria (information gain and Gini coefficient), evaluates the performance of each one on the validation set, and prints the resulting accuracies of each model. You should use DecisionTreeClassifier, but you should write the validation code yourself. Include the output of this function in your solution PDF (hw1_writeup.pdf).
(d) [3pts] Write a function compute_information_gain which computes the information gain of a split on the training data. That is, compute I(Y,xi), where Y is the random variable signifying whether the headline is real or fake, and xi is the keyword chosen for the split.
Report the outputs of this function for the topmost split from the previous part, and for several other keywords.
3. [8pts] Regularized Linear Regression. For this problem, we will use the linear regression model from the lecture:
D y = Xwjxj + b.
j=1
In lecture, we saw that regression models with too much capacity can overfit the training data and fail to generalize. We also saw that one way to improve generalization is regularization: adding a term to the cost function which favors some explanations over others. For instance, we might prefer that weights not grow too large in magnitude. We can encourage them to stay small by adding a penalty:
to the cost function, for some λ > 0. It is also possible to apply different regularization penalties in each dimension. The formulation would be:
where i indexes the data points, βj ≥ 0 for all j, and J is the same squared error cost function from lecture. Note that in this formulation, there is no regularization penalty on the bias parameter. Also note that when βj = 0, you don’t apply any regularization on j-th dimension. For this question, show your work in detail as most points are allocated in showing how you obtained your answer.
(a) [3pts] Determine the gradient descent update rules for the regularized cost function Jregβ . Your answer should have the form:
wj ← ··· b ← ···
This form of regularization is sometimes called “weight decay”. Based on this update rule, why do you suppose that is?
(b) [3pts] It’s also possible to solve the regularized regression problem directly by setting the partial derivatives equal to zero. In this part, for simplicity, we will drop the bias term from the model, so our model is:
D y = Xwjxj.
j=1
It is possible to derive a system of linear equations of the following form for Jregβ :
.
Determine formulas for Ajj0 and cj.
(c) [2pts] Based on your answer to part (b), determine formulas for A and c, and derive a closed-form solution for the parameter w. Note that, as usual, the inputs are organized into a design matrix X with one row per training example.




Reviews
There are no reviews yet.