(有解题思路)机器学习coursera吴恩达第六周最后测验习题汇总
第六周的习题做了三遍才100%正确,其中还是参照了不少论坛里大神的答案(比如BeiErGeLaiDe的博客,链接点击打开链接)
正式进入主题:ML第六周最后测验,共五题。文中大部分属于个人观点,如有错误欢迎指正、交流。
1. You are working on a spam classification system using regularized logistic regression. "Spam" is a positive class (y = 1) and "not spam" is the negative class (y = 0). You have trained your classifier and there are m = 1000 examples in the cross-validation set. The chart of predicted class vs. actual class is:
Actual Class: 1 | Actual Class: 0 | |
Predicted Class: 1 | 85 | 890 |
Predicted Class: 0 | 15 | 10 |
For reference:
· Accuracy = (true positives + true negatives) / (total examples)
· Precision = (true positives) / (true positives + false positives)
· Recall = (true positives) / (true positives + false negatives)
· F1 score = (2 * precision * recall) / (precision +recall)
What is the classifier's accuracy (as avalue from 0 to 1)?
Enter your answer in the box below. If necessary, provide at least two values after the decimal point.
答:第一题我抽到的三次都不一样,反正是把精度Accuraccy、查准率precision、查全率recall全算了一遍,算是基础题目。
精度Accuraccy = ( 85+10)/1000 = 0.095;
recall = 85 / (85+15) = 0.85
precision = 85/(85+890) = 0.087
F1 = 2*0.085*0.087/(0.087+0.85)=0.16(题意,精确到小数点后两位)2. Suppose a massive dataset is available for training a learning algorithm. Training on a lot of data is likely to give good performance when two of the following conditions hold true.
Which are the two?
Our learning algorithm is able to represent fairly complex functions (for example, if we train a neural network or other model with a large number of parameters).
A human expert on the application domain can confidently predict y when given only the features x (or more generally, if we have some way to be confident that x contains sufficient information to predict y accurately).
When we are willing to include high order polynomial features of x (such as x21, x22, x1x2, etc.).
The classes are not too skewed.
答:A,我们的学习算法能够表示相当复杂的功能(例如,如果我们训练神经网络或其他具有大量参数的模型)。模型复杂,表示复杂的函数,此时的特征多项式可能比较多,能够很好的拟合训练集中的数据,使用大量的数据能够很好的训练模型。
B:当只给出特征x(或者更一般来说,如果我们有办法可以确信x包含足够的信息来准确预测y),在应用型领域的专家可以相当准确地预测y。 数据的有效性,使数据本身有一定规律可循。
3. Suppose you have trained a logistic regression classifier which is outputing hθ(x).
Currently, you predict 1 if hθ(x)≥threshold, and predict 0 if hθ(x)<threshold, where currently the threshold is set to 0.5.
Suppose you decrease the threshold to 0.1. Which of the following are true? Check all that apply.
The classifier is likely to have unchanged precision and recall, and thus thesame F1 score.
The classifier is likely to have unchanged precision and recall, but higher accuracy.
The classifier is likely to now have lower recall.
The classifier is likely to now have lower precision.
答:选第四个。这题还有一个版本是将阈值threshould提升到0.9的,答案和这个这个0.7的是一样的。
首先阈值的设定并不会影响查全率recall和查准率precision,recall和precision是此消彼长的一个过程,吴恩达老师课程里讲到的那个图可以帮助理解这个题 threshould设定愈高查准率precision越高,而对应的查全率recall则越低,反之,precision和recall也相反。如果阈值时0.7或者0.9,那么精度accuraccy则越高,因为accuraccy = (true positives + true negatives) / (total examples) ,阈值threshould增加,说明precision查准率升高了,那么 true positives升高,所以更高的accuraccy。
4. Suppose you are working on a spam classifier, where spam emails are positive examples (y=1) and non-spam emails are negative examples (y=0). You have a training set of emails in which 99% of the emails are non-spam and the other 1% is spam. Which of the following statements are true? Check all that apply.
If you always predict non-spam (output y=0), your classifier will have 99% accuracy on the trainingset, but it will do much worse on the cross validation set because it has overfit the training data.
A good classifier should have both a high precision and high recall on the cross validation set.
If you always predict non-spam (output y=0), your classifier will have 99% accuracy on the training set, and it will likely perform similarly on the cross validation set.
If you always predict non-spam (output y=0), your classifier will have an accuracy of 99%.
5. Which of the following statements are true? Check all that apply.
The"error analysis" process of manually examining the examples whichyour algorithm got wrong can help suggest what are good steps to take (e.g., developing new features) to improve your algorithm's performance.
Itis a good idea to spend a lot of time collecting a large amount of data before building your first version of a learning algorithm.
If your model is underfitting the training set, then obtaining more data is likely to help.
After training a logistic regression classifier, you must use 0.5 as your threshold for predicting whether an example is positive or negative.
Using a very large training set makes it unlikely for model to overfit the training data.
答:选A、E。
手动检查你的算法出错的例子如“错误分析”过程可以帮助建议采取什么好办法(例如,开发新功能)来改进算法的性能。
使用非常大的训练集使模型不太可能过拟合训练数据。
这题答案主要参考以上刘亚龙大神的解析,
注:误差分析计算可以得出各因素对模型性能的影响,可以通过这种计算的方法判断如何改进模型性能,所以A正确;B错,数据还要保证方便符合模型和计算,最重要的是要有一定的潜在规律可循,多而不乱,即找大量有用的数据,而不仅仅是大量数据;C里面已经是underfitting了,可能为模型太简单,特征太少(比如用来拟合数据仅仅只是一次线性函数,那肯定不行,再多的数据也无法正确拟合,此时应该做的是尝试增加更多的多项式特征)或者课上提到的数据太多(或者说数据太杂);D里面must use不对,考虑到Skewed Data,不一定最终把threshold设为0.5;E很明显正确,可以参照课上overfitting和underfitting的定义;
结束
附:测验长截图