Linear Regression basics
Modeling
我们使用以下 notation:
(generalized) linear regression 的定义: 给定 个 data points where each , 以及预先设定好的 个 basis functions 用以表示 个 features;
我们通过建立一个 , 使其关于 线性, 以找到一组参数 , 使得 能够近似 for each , with respect to the loss function we define to measure the distance between two vectors.
其中 $$
Remark: 注意 linear regression 指的是 和参数 之间是 linear 的, 而不是说 和 input 之间是 linear 的. 我们可以选择 nonlinear 的 basis funtions 来 encode 来表示 features 的特性, 比如我们可以选择:
loss function: sum of squared error
这个 loss function 衡量两个 vectors 之间的距离, 目的是衡量 和 这两个 vectors 的差距. 实际上就是它们 difference 的 -norm 的平方.
sum of squares error: $$
gradient of sum of squared error
我们下面首先通过求 的每个 entry 来写出这个 gradient.
因而 vectorize:
batch v.s. stochastic GD
我们通过迭代降低 gradient 来降低 loss function 的值, 从而优化 weight vector.
(More practically, 我们可以采用 minibatch SGD: 即在 batch GD 和 SGD 之间, 每次选择一小部分 samples, 称为一个 minibatch, 在这个 minibatch 上进行 GD.)
vectorization
我们可以把每个 的 features 写成一个 row vector, 并 stack up 个 row vectors, 成为一个 的 matrix . 从而: $$
vector form gradient 以及 closed-form sol
如果 $E$ 是个 convex 的函数, 那么一定是 global min!**)
为了计算 closed form solution, 我们首先要给出 的 matrix form 表达式. \ 这里首先引入 linear form 和 quadratic form 的 gradient:
我们发现: 就是一个 的 quadratic form, 一个 的 linear form 和一个 const 的组合. 从而可以求出:
从而我们得到 closed form solution (if exists):
因而 closed form exists iff 可逆, iff 可逆. 并且 recalll in linear algebra: . 因而, closed form exists iff 且
overfitting
overfitting 的原因: features 数量 M 设置得太多, 导致过度保持 training sets 的点靠近曲线, 但是对于 testing set 并不对( 这里是一个简化, 实则不能单纯这样划分, 需要 cross validation)
overfitting 的表现: 各项 features 的参数动荡很大.
overfitting 的解决方法 1: 增加数据点
overfitting 的解决方法 2:
regularization: solving overfit
我们通过引入一个 regularization term, 也称为 penalty term 惩罚项, 以使得曲线尽量平缓, 从而减少 overfitting.
Idea: 把 本身的 Magnitute 作为一个 loss function 的一部分, 让我们降低 loss 的同时自带降低 w 的各个 entries 的正负动荡程度, 从而使得拟合曲线尽量平缓, 降低曲线的 expressibility.
这里的 理应设置较小, 如 0.001 等.
设置越大, 曲线越接近 constant. 比如 , 则会
如果 traning error 和 testing error 都很大, 那就说明 调太大了.
gradient of regularized least square
summary: regularization controls the tradeoff bewteen fitting error 和 expressibility.
Linear Regression(lec3)
Review on Probability
Likelihood function
Likelihood function (似然函数) 表示在给定一组 i.i.d 的数据 samples 以及其以 为参数的分布形式下,random vector = 处的概率密度;其以参数 为变量,表达的是在固定数据 的前提下,不同参数 对数据的适配程度
而 maximum likelihood estimator 则是使得这个 random vector = 处的概率密度 maximize 的参数
由于独立同分布, random vector = 处的概率密度就等于所有 处的概率密度的 product.
取得 maximum likelihood estimator 即: 在这个参数下, 我们得到的模型, 对于我们的训练数据而言, 取得其相对的 y 的概率密度最大.
Find MLE for linear model with stochastic noise
(求解MLE 可得: linear model with stochastic noise which is normal distributed centered at 0 得到的 MLE,与标准的 linear model 得到的 MLS 最优解是等价的.
这是符合直觉的,因为一个正态分布的 noise 不影响参数的选择)
locally weighted linear regression