ML_Note:bias VS variance

来源:互联网 发布:java bigdecimal 相加 编辑:程序博客网 时间:2024/06/17 15:56

这次主要总结一下,如何诊断学习曲线,如何判断我们进行拟合数据的时候是处于高偏差(bias),还是处于刚方差 (variance).以及我们应该采取的行动.

Deciding What to Try Next

Errors in your predictions can be troubleshooted by:

1、Getting more training examples

2、Trying smaller sets of features

3、Trying additional features

4、Trying polynomial features

5、Increasing or decreasing λ

Evaluating a Hypothesis

我们怎么才知道我们所做的模型是好还是坏呢? 我们可以这样做把训练数据(train set)分为两部分,一部分是作为训练集(train set),一部分作为测试集(test set).我们从训练集中训练数据,然后把的到的 Θ 应用到测试集计算他的误差(test error),即计算costFunction 在测试集上的cost.一般来说建议 7:3 分集合.

对于线性回归来说,

test_error=12mmi=1(hθ(x(i)yi))2

对于分类(classifier),logistic 回归问题来说,

err(hθ(x(i)),yi)=1 if  0

test_error=1mtestmtseti=1err(hθ(x(i)),yi)

Model Selection and Train/Validation/Test Sets

仅仅只是因为在测试集上的误差最小还说明不了什么问题,有可能你选着的模型都是错的,所以我们需要用一些方法选择一个好的模型。

交叉验证方法

我们引入第3个集合交叉验证集(cross validation set),来寻找最优的模型,对于线性回归来说我们需要找到一个比较优化的次数(degree),当然也可以不用这个(cross validation set),而直接采用(test set),不过这样的化,test set 的误差就是经过优化了的,所以不建议使用这种方式.

With the Validation Set (note: this method presumes we do not also use the CV set for regularization)

1、Optimize the parameters in Θ using the training set for each polynomial degree.

2、Find the polynomial degree d with the least error using the cross validation set.

3、Estimate the generalization error using the test set with Jtest(Θ(d)), (d = theta from >polynomial with lower error);

This way, the degree of the polynomial d has not been trained using the test set.

所有的验证集合的误差计算的时候都是不需要加入正则化参数( λ) 的.

Diagnosing Bias vs. Variance

图片说明一切

对于高偏差(bias)与高方差(Variance),可以这样想,当次数 d 比较大的时候,对于训练数据来说肯定是拟合的比较好的(overfitting),所以误差比较小,可是对于训练集来说就不是这样的,关于这个,在一些数值计算里面也有提到.

Regularization and Bias/Variance

lambda 变化图
这个再讲正则化(regression)的时候是有讲到的.

正则化的一般步骤
这里写图片描述

for i = 1:length(lambda_vec)  lambda = lambda_vec(i);  [theta] = trainLinearReg(X,y,lambda);  error_train(i) = linearRegCostFunction(X,y,theta,0);  error_val(i) = linearRegCostFunction(Xval,yval,theta,0);end;

Learning Curves

我们画出 JtrainJcv 关于训练集大小的学习曲线.

 学习曲线

学习曲线2

Deciding What to Do Next Revisited

这里写图片描述

参考

链接 week 6

0 0
原创粉丝点击