Predictive Modeling
the goal is predictive modeling
features: x ∈ X x \in X x ∈ X where x x x is the tiger image and X X X is the space of all images of animals
labels y ∈ Y y \in Y y ∈ Y and y = [ 0 , 1 , 0 ] y = [0, 1, 0] y = [ 0 , 1 , 0 ]
then we could have a function that tells us our prediction f ( x ) = y ^ f(x) = \hat{y} f ( x ) = y ^
this class is about how to design the function, which is our deep neural network
Data Generating Process
our features are generated by some unknown model P ( x ) \mathbb{P}(x) P ( x ) : x ∼ P ( x ) x \sim \mathbb{P}(x) x ∼ P ( x ) , so we want to predict the target label based on the input features y ∼ P ( y ∣ x ) y \sim \mathbb{P}(y|x) y ∼ P ( y ∣ x )
Because P \mathbb{P} P are distributions we don't know / are unknown but assume exist, we want our predictive model to match this: f ( x ) ≈ P ( y ∣ x ) f(x) \approx \mathbb{P}(y|x) f ( x ) ≈ P ( y ∣ x ) .
Training Data
D = { ( x n , y n ) } n = 1 N \mathbb{D} = {\{(x_n, y_n)\}}^{N}_{n=1} D = {( x n , y n )} n = 1 N
x n ∼ P ( x ) x_n \sim \mathbb{P}(x) x n ∼ P ( x )
y n ∼ P ( y ∣ x n ) y_n \sim \mathbb{P}(y|x_n) y n ∼ P ( y ∣ x n )
Linear Regression
Univariate Linear Regression
x ∈ R x \in \mathbb{R} x ∈ R , y ∈ R y \in \mathbb{R} y ∈ R
f ( x ; w ) = w ⋅ x f(x;w) = w \cdot x f ( x ; w ) = w ⋅ x
This is the simplest model you can think of
w w w is the slope. It's the parameter that we want to determine from the training data
Squared Loss
We want to come up with a loss function to determine how far we are off of the actual data.
P ( w ; D ) = 1 N ∑ n = 1 N l ( w , x n , y n ) = 1 N ∑ n = 1 N ( f ( x , w ) − y n ) 2 \displaystyle P(w;\mathbb{D}) = \frac{1}{N}\sum_{n=1}^{N}l(w, x_n, y_n) = \frac{1}{N}\sum_{n=1}^{N}(f(x, w) - y_n)^2 P ( w ; D ) = N 1 n = 1 ∑ N l ( w , x n , y n ) = N 1 n = 1 ∑ N ( f ( x , w ) − y n ) 2
aka mean squared error
think hard about what you are encoding. what assumptions is this loss function baking in. in this case, we ignore the negative, which means it would not be optimal for like an auction bidding model because it will think overbidding is okay.
w ∗ = arg min w l ( w ; D ) = arg min w 1 N ∑ N ( w ⋅ X n − y n ) 2 w^* = \arg\min_w l(w; \mathbb{D}) = \arg\min_w \frac{1}{N}\sum_{N}(w \cdot X_n - y_n)^2 w ∗ = arg min w l ( w ; D ) = arg min w N 1 ∑ N ( w ⋅ X n − y n ) 2 where w ⋅ X n w \cdot X_n w ⋅ X n is f ( x ; w ) f(x;w) f ( x ; w )
To solve for w w w :
step 1: take the derivative
d d w l ( w ; D ) = d d w [ 1 N ∑ N ( w ⋅ X n − y n ) 2 ] = 2 N { ( ∑ n = 1 N w ⋅ x n 2 ) − ( ∑ n = 1 N y n ⋅ x n ) } \frac{d}{dw} l(w; D) = \frac{d}{dw}[\frac{1}{N}\sum_{N}(w \cdot X_n - y_n)^2] = \frac{2}{N}\{(\sum_{n=1}^{N}w\cdot {x_n}^2)-(\sum_{n=1}^{N}y_n \cdot x_n)\} d w d l ( w ; D ) = d w d [ N 1 ∑ N ( w ⋅ X n − y n ) 2 ] = N 2 {( ∑ n = 1 N w ⋅ x n 2 ) − ( ∑ n = 1 N y n ⋅ x n )}
step 2: set to 0 and solve for w w w
0 = d d w l ( w ; D ) 0 = \frac{d}{dw} l(w; D) 0 = d w d l ( w ; D ) ⇒ w ∗ = ∑ n = 1 N y n ⋅ x n ∑ n = 1 N x n 2 \Rightarrow w^* = \frac{\sum_{n=1}^{N}y_n \cdot x_n}{\sum_{n=1}^{N}{x_n}^2} ⇒ w ∗ = ∑ n = 1 N x n 2 ∑ n = 1 N y n ⋅ x n
You can take this w w w and use it to make predictions !
Vectorized Version
x ⃗ = [ x 1 ⋯ x N ] T \vec{x} = [x_1 \cdots x_N]^T x = [ x 1 ⋯ x N ] T
y ⃗ = [ y 1 ⋯ y N ] T \vec{y} = [y_1 \cdots y_N]^T y = [ y 1 ⋯ y N ] T
w ∗ = X T Y X T X w^* = \frac{X^TY}{X^TX} w ∗ = X T X X T Y
Maximum Likelihood
Statistical Divergences
Ways of computing divergences between values
kullback-leibler divergence (KLD)
K L D [ p ( z ) ∣ ∣ q ( z ) ] ≜ E p ( z ) [ l o g p ( z ) q ( z ) ] KLD[p(z) || q(z)] \triangleq \mathbb{E}_{p(z)}[log\frac{p(z)}{q(z)}] K L D [ p ( z ) ∣∣ q ( z )] ≜ E p ( z ) [ l o g q ( z ) p ( z ) ] = ∫ z p ( z ) l o g p ( z ) q ( z ) d z \int_z p(z) log \frac{p(z)}{q(z)}dz ∫ z p ( z ) l o g q ( z ) p ( z ) d z
isn't a true distance metric but is a good one to use
the amount (bits) of information loss between p(z) and q(z).
there are other divergences like Hellinger divergence (a type of f divergences)
Use this to quantify how close the predictive model is to y ∼ P y \sim \mathbb{P} y ∼ P (the true model)
Predictive Models as Distributions
p ( y ; Θ = f ( x ) ) p(y;\Theta = f(x)) p ( y ; Θ = f ( x ))
normal distribution N ( y , μ , σ 2 ) = N ( y , μ = f ( x ) , θ 0 2 N(y, \mu, \sigma^2) = N(y, \mu = f(x), {\theta_0}^2 N ( y , μ , σ 2 ) = N ( y , μ = f ( x ) , θ 0 2
imagine at every point in that y = w x y=wx y = w x there is a normal distribution. The mean is governed by that line.
Entropy is how uncertain a distribution in. E.g., the fair coin has a high entropy, a skewed coin has a low entropy because you can predict what value the coin will take. Entropy: H [ p ( z ) ] ≜ E p ( z ) [ − l o g p ( z ) ] \mathbb{H}[p(z)]\triangleq\mathbb{E}_{p(z)}[-log p(z)] H [ p ( z )] ≜ E p ( z ) [ − l o g p ( z )]
Maximum Likelihood Estimation
K L D [ P ( y ∣ x ) ∣ ∣ p ( y ; Θ = f ( x ) ) ] KLD[\mathbb{P}(y|x) || p(y;\Theta = f(x))] K L D [ P ( y ∣ x ) ∣∣ p ( y ; Θ = f ( x ))] between true distribution and the model we have defined where the mean is governed by our f ( x ) f(x) f ( x ) function. this whole equation represents the bits or information lost
= E P ( y ∣ x ) [ l o g P ( y ∣ x ) p ( y ; Θ = f ( x ) ) ] = E P ( y ∣ x ) [ l o g P ( y ∣ x ) ] − E P ( y ∣ x ) [ l o g p ( y ; Θ = f ( x ) ) ] = E P ( y ∣ x ) [ − l o g p ( y ; Θ = f ( x ) ) ] − H [ P ( y ∣ x ) ] =\mathbb{E}_{\mathbb{P}(y|x)}[log\frac{\mathbb{P}(y|x)}{p(y;\Theta = f(x))}]=\mathbb{E}_{\mathbb{P}(y|x)}[log\mathbb{P}(y|x)] - \mathbb{E}_{\mathbb{P}(y|x)}[log p(y;\Theta = f(x))] = \mathbb{E}_{\mathbb{P}(y|x)}[-log p(y;\Theta = f(x))] - \mathbb{H}[\mathbb{P}(y|x)] = E P ( y ∣ x ) [ l o g p ( y ; Θ = f ( x )) P ( y ∣ x ) ] = E P ( y ∣ x ) [ l o g P ( y ∣ x )] − E P ( y ∣ x ) [ l o g p ( y ; Θ = f ( x ))] = E P ( y ∣ x ) [ − l o g p ( y ; Θ = f ( x ))] − H [ P ( y ∣ x )]
Note that H [ P ( y ∣ x ) ] \mathbb{H}[\mathbb{P}(y|x)] H [ P ( y ∣ x )] doesnt involve f(x) !
Now we set up an optimization problem with respect to f ( x ) f(x) f ( x ) .
w ∗ = arg min w E p ( x ) E P ( y ∣ x ) [ − l o g p ( y ; f ( x ) ; w ) ] + entropy constant w^* = \arg\min_{w} \mathbb{E}_{p(x)}\mathbb{E}_{\mathbb{P}(y|x)}[-log p(y;f(x);w)] + \text{entropy constant} w ∗ = arg min w E p ( x ) E P ( y ∣ x ) [ − l o g p ( y ; f ( x ) ; w )] + entropy constant
entropy constant will go away when you take the derivative
you can't do this because it assumes you are doing sums or integrals over distributions we don't know.
Monte Carlo Approximation
E p ( x ) [ ψ ( x ) ] ≈ 1 S ∑ S ψ ( x ^ s ) \mathbb{E}_{p(x)}[\psi(x)]\approx \frac{1}{S} \sum_S \psi(\hat{x}_s) E p ( x ) [ ψ ( x )] ≈ S 1 ∑ S ψ ( x ^ s )
A very important formula:
w ∗ = arg min w K L D [ P ( y ∣ x ) ∣ ∣ p ( y ; Θ = f ( x , w ) ) ] w^* = \arg\min_w KLD[\mathbb{P}(y|x) || p(y;\Theta = f(x,w))] w ∗ = arg min w K L D [ P ( y ∣ x ) ∣∣ p ( y ; Θ = f ( x , w ))]
≈ arg min w − 1 N ∑ n = 1 N log p ( y n ; f ( x n , w ) ) \approx \arg\min_w -\frac{1}{N} \sum^N_{n=1} \log p(y_n; f(x_n, w)) ≈ arg min w − N 1 ∑ n = 1 N log p ( y n ; f ( x n , w ))
if you have only 5 samples to learn from, then it's bad
dataset size is the engine that drives how good you are learning
KLD must be zero for it to be perfect predictor
simplifying this last form gets you the squared error function.