1 Evaluating the Hypothesis

1.1 Training / Testing Procedure

Training sets Testing sets
70% 30%
(x(1),y(1))(x(m),y(m))(x^{(1)},y^{(1)})···(x^{(m)},y^{(m)}) (xtest(1),ytest(1))(xtest(mtest),ytest(mtest))(x_{test}^{(1)},y_{test}^{(1)})···(x_{test}^{(m_{test})},y_{test}^{(m_{test})})

datas are all randomly ordered

1.1.1 for Linear Regression

  1. Learn parameter θ\theta from training data
  2. Compute test set error:
    Jtest(θ)=12mtesti=1mtest(hθ(xtest(i))ytest(i))2J_{test}(\theta)=\frac{1}{2m_{test}}\sum_{i=1}^{m_{test}}{(h_\theta(x_{test}^{(i)})-y_{test}^{(i)})}^2

1.1.2 for Logistic Regression

  1. Learn parameter θ\theta from training data
  2. Compute test set error:

way(1)

Jtest(θ)=1mtesti=1mtest(ytest(i)loghθ(xtest(i))+(1ytest(i))loghθ(xtest(i)))J_{test}(\theta)=-\frac{1}{m_{test}}\sum_{i=1}^{m_{test}}\left(y_{test}^{(i)}\text{log}h_\theta(x_{test}^{(i)})+(1-y_{test}^{(i)})\text{log}h_\theta(x_{test}^{(i)})\right)

way(2)

0/1 misclassification error:
err(hθ(x),y)={1,if h(x)0.5 and y=0, or h(x)0.5 and y=10,otherwiseerr(h_\theta(x),y)=\begin{cases} 1,&\text{if $h(x)≥0.5$ and $y=0$, or $h(x)<0.5$ and $y=1$}\\ 0,&\text{otherwise} \end{cases}
Test  error=1mtesti=1mtesterr(hθ(xtest(i)),ytest(i))Test\ \ error=\frac{1}{m_{test}}\sum_{i=1}^{m_{test}}err(h_\theta(x_{test}^{(i)}),y_{test}^{(i)})

2 Model Selection and Training / Validation / Test sets(交叉验证集)

Training set Cross validation set Test set
60% 20% 20%
(x(1),y(1))(x(m),y(m))(x^{(1)},y^{(1)})···(x^{(m)},y^{(m)}) (xcv(1),ycv(1))(xcv(mcv),ycv(mcv))(x_{cv}^{(1)},y_{cv}^{(1)})···(x_{cv}^{(m_{cv})},y_{cv}^{(m_{cv})}) (xtest(1),ytest(1))(xtest(mtest),ytest(mtest))(x_{test}^{(1)},y_{test}^{(1)})···(x_{test}^{(m_{test})},y_{test}^{(m_{test})})
  • Training error:
    Jtrain(θ)=12mi=1m(hθ(x(i))y(i))2J_{train}(\theta)=\frac{1}{2m}\sum_{i=1}^m{\left(h_\theta(x^{(i)})-y^{(i)}\right)}^2
    Cross Validation error:
    Jcv(θ)=12mcvi=1mcv(hθ(xcv(i))ycv(i))2J_{cv}(\theta)=\frac{1}{2m_{cv}}\sum_{i=1}^{m_{cv}}{\left(h_\theta(x_{cv}^{(i)})-y_{cv}^{(i)}\right)}^2
    Test error:
    Jtest(θ)=12mtesti=1mtest(hθ(xtest(i))ytest(i))2J_{test}(\theta)=\frac{1}{2m_{test}}\sum_{i=1}^{m_{test}}{\left(h_\theta(x_{test}^{(i)})-y_{test}^{(i)}\right)}^2
  • Model selection:
    1° 使用训练集训练出nn个模型
    2° 用nn个模型分别对交叉验证集计算得出交叉验证误差(代价函数的值)
    3° 选取代价函数值最小的模型
    4° 用步骤3°中选出的模型对测试集计算得出推广误差(代价函数的值)

3 Diagnosing Bias(偏差,欠拟合) vs. Variance(方差,过拟合)

【机器学习】5 应用机器学习的建议

Bias(Underfit) Variance(overfit)
Jtrain(θ)J_{train}(\theta) will be high Jtrain(θ)J_{train}(\theta) will be low
Jcv(θ)Jtrain(θ)J_{cv}(\theta)≈J_{train}(\theta) Jcv(θ)>>Jtrain(θ)J_{cv}(\theta)>>J_{train}(\theta)

3.1 Regularization and Bias / Variance

【机器学习】5 应用机器学习的建议

3.2 Learning Curves

  • 将训练集误差和交叉验证集误差作为训练集实例数量mm的函数绘制的图表

3.2.1 High Bias

【机器学习】5 应用机器学习的建议

3.2.2 High Variance

【机器学习】5 应用机器学习的建议

3.2.3 Solutions

to solve high bias to solve high variance
Try getting additional features Get more training examples
Try adding polynomial features Try smaller sets of features
Try decreasing λ\lambda Try increasing λ\lambda

4 Nerual networks and overfitting

“small” neural network “large” neural network
fewer parameters more parameters
more prone to underfitting more prone to overfitting
computationally cheaper computationally more expensive
use regularization(λ\lambda)to address overfitting

5 Reference

吴恩达 机器学习 coursera machine learning
黄海广 机器学习笔记

相关文章: