Homework_Week3_Coursera【Machine Learning】AndrewNg、Logistic Regression、Regularization
- Logistic Regression
- 1.Suppose that you have trained a logistic regression classifier, and it outputs on a new example xx a prediction htheta*(x) = 0.7. This means (check all that apply):
- 【wrong】2.Suppose you have the following training set, and fit a logistic regression classifier
- 3. For logistic regression, the gradient is given by XXX . Which of these is a correct gradient descent update for logistic regression with a learning rate of \alphaα? Check all that apply.
- 4. Which of the following statements are true? Check all that apply.
- 5.Suppose you train a logistic classifier XXX. Which of the following figures represents the decision boundary found by your classifier?
- 结果
- Regularization
- 1.You are training a classification model with logistic regression. Which of the following statements are true? Check all that apply.
- 2. Suppose you ran logistic regression twice, once with \lambda =0λ=0, and once with \lambda = 1λ=1. One of the times, you got parameters
- 3. Which of the following statements about regularization are true? Check all that apply.
- 4.In which one of the following figures do you think the hypothesis has overfit the training set?
- 5.In which one of the following figures do you think the hypothesis has underfit the training set?
- 结果
Logistic Regression
1.Suppose that you have trained a logistic regression classifier, and it outputs on a new example xx a prediction htheta*(x) = 0.7. This means (check all that apply):
解析:
假设你训练了一个逻辑回归分类器,输出了新例子h(x)=0.7 意味着预测正案例y=1的概率为0.7,y=0为0.3
答案: BC
【wrong】2.Suppose you have the following training set, and fit a logistic regression classifier
解析: 只有(2,1)点标签为1,其余三点看似在一个圈上,为0标签
A正确的,J是一个凸函数,会向全局最优最小值靠拢、正确
B说增加多项式特征,会增加我们对于数据的适应度,看具体情况和数据分布 正确
C说正负样本不会被一条直线分开,所以梯度下降会失败 错误
D因为正负样本不能被一条直线分开,线性回归表现和逻辑回归一样,应该是不一样的,故错误
答案: BC
正确答案: AB
3. For logistic regression, the gradient is given by XXX . Which of these is a correct gradient descent update for logistic regression with a learning rate of \alphaα? Check all that apply.
解析: D选项theta^T*x是线性回归,不是逻辑回归的,B选项中x没有下标
答案: AC
4. Which of the following statements are true? Check all that apply.
解析:
由sigmoid图像得知A正确
B选项,用一个由线性回归得到的阈值进行分类的线性回归不可能对分类任务预测的很好的,错误
C选项采用别的advanced optimization algorithm是为了找alpha学习率,不是导致向局部最小的原因
D正确,J是损失函数,多少大于0,最好也就等于0
答案: AD
5.Suppose you train a logistic classifier XXX. Which of the following figures represents the decision boundary found by your classifier?
解析: 令括号中为f(x)代入即可,f(x)=x2-6+theta1*x1
故 x2=6时,x1可以取得任何数,故选CD中的一个
f(x)>0时,g(f(x))>0
所以在x2>6时,为1
答案: D
结果
Regularization
1.You are training a classification model with logistic regression. Which of the following statements are true? Check all that apply.
解析:
A说太多特征会让模型更容易过拟合 正确,所以才需要PCA数据降维,主成分分析等等,舍去一些细枝末节的
B正则化会让模型总是在样本中效果更好而在训练集中不会 错误
C正则规范化总是让训练集结果更好、不一定更好,可能会损失一部分训练集的特点,以便于更好的符合测试集合、解决过拟合问题 所以错误
D增加新特征是的模型在测试案例上表现更好而非训练集、增加更多新特征其实是对training set更好,因为更拟合了,反而不利于预测新样本 错误
答案: A
2. Suppose you ran logistic regression twice, once with \lambda =0λ=0, and once with \lambda = 1λ=1. One of the times, you got parameters
解析: lamda大了,theta值对应的应该是小的
答案: B
3. Which of the following statements about regularization are true? Check all that apply.
解析:
选正确的
A说因为正则化导致损失函数不再突出,(光滑曲线,解决过拟合问题)梯度下降不总是向着全局最优前进 错误 其实是向着全局最优解再走,如果考虑到测试集的话
B用大的lamda会让假设的表现受影响,我们唯一不设置lamda过大的原因就是为了避免数值问题、记得不是为了解决过拟合问题吗
C 用太大的lamda会导致欠拟合,正确
D因为逻辑回归输出值在0-1之间,不断地缩小,正则化对它没帮助、说的不是一回事
答案: C
4.In which one of the following figures do you think the hypothesis has overfit the training set?
解析: 过拟合直接A,完全贴合数据样本
答案: A
5.In which one of the following figures do you think the hypothesis has underfit the training set?
解析: underfit是欠拟合
B是过拟合 C是正常拟合 D也没太大毛病,最右下角的是噪音数据
A选项是属于欠拟合
答案: A