Skip to content

Commit 603ba43

Browse files
committed
Upload CS229 problem set 3
1 parent 58e7f79 commit 603ba43

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"This question asks to prove that maxmizing variance with the first principal component from PCA is equivalent to minimize the mean squared error (MSE)."
8+
]
9+
},
10+
{
11+
"cell_type": "markdown",
12+
"metadata": {},
13+
"source": [
14+
"Given a unit vector $u$, the projection of $x$ onto it is \n",
15+
"\n",
16+
"$$\n",
17+
"f_u(x) = (u^T x) u\n",
18+
"$$"
19+
]
20+
},
21+
{
22+
"cell_type": "markdown",
23+
"metadata": {},
24+
"source": [
25+
"Then,\n",
26+
"\n",
27+
"\\begin{align*}\n",
28+
"\\mathrm{MSE}\n",
29+
"&= \\frac{1}{m} \\sum_{i=1}^m \\left \\| x^{(i)} - f_u(x^{(i)}) \\right \\|_2^2 \\\\\n",
30+
"&= \\frac{1}{m} \\sum_{i=1}^m \\bigg( \\big(x^{(i)} - (u^T x^{(i)})u \\big)^T \\big(x^{(i)} - (u^T x^{(i)})u \\big) \\bigg )\\\\\n",
31+
"&= \\frac{1}{m} \\sum_{i=1}^m \\bigg( (x^{(i)})^Tx^{(i)} - \\big( (u^T x^{(i)})u \\big)^T x^{(i)} - (x^{(i)})^T\\big( (u^T x^{(i)})u \\big) + \\big( (u^T x^{(i)})u \\big)^T \\big( (u^T x^{(i)})u \\big) \\bigg ) \\\\\n",
32+
"&= \\frac{1}{m} \\sum_{i=1}^m \\bigg( (x^{(i)})^Tx^{(i)} - 2 (u^T x^{(i)}) (u ^T x^{(i)}) + (u^T x^{(i)})^2 (u^Tu) \\bigg ) \\\\\n",
33+
"&= \\frac{1}{m} \\sum_{i=1}^m \\bigg( (x^{(i)})^Tx^{(i)} - (u^T x^{(i)})^2 \\bigg ) \\\\\n",
34+
"&= \\frac{1}{m} \\sum_{i=1}^m (x^{(i)})^Tx^{(i)} - \\frac{1}{m} \\sum_{i=1}^m (u^T x^{(i)})^2 \\\\\n",
35+
"&= \\frac{1}{m} \\sum_{i=1}^m (x^{(i)})^Tx^{(i)} - \\bigg( \\frac{1}{m} \\sum_{i=1}^m u^T x^{(i)} \\bigg)^2 - \\mathrm{Var}(u^Tx^{(i)})\n",
36+
"\\end{align*}"
37+
]
38+
},
39+
{
40+
"cell_type": "markdown",
41+
"metadata": {},
42+
"source": [
43+
"Compared to the equation in the problem set, I added $\\frac{1}{m}$ to the MSE, which won't affect the minization/maximization problem.\n",
44+
"\n",
45+
"The last equality uses the fact about variance and mean that is $E[(X - \\bar X)^2] = (E[X])^2 - E[(X^2)]$.\n",
46+
"\n",
47+
"This proves that maximizing the variance is equivalent to minimizing the MSE."
48+
]
49+
}
50+
],
51+
"metadata": {
52+
"anaconda-cloud": {},
53+
"kernelspec": {
54+
"display_name": "Python 3",
55+
"language": "python",
56+
"name": "python3"
57+
},
58+
"language_info": {
59+
"codemirror_mode": {
60+
"name": "ipython",
61+
"version": 3
62+
},
63+
"file_extension": ".py",
64+
"mimetype": "text/x-python",
65+
"name": "python",
66+
"nbconvert_exporter": "python",
67+
"pygments_lexer": "ipython3",
68+
"version": "3.5.1"
69+
}
70+
},
71+
"nbformat": 4,
72+
"nbformat_minor": 2
73+
}

0 commit comments

Comments
 (0)