1. 程式人生 > >【Machine Learning】【Andrew Ng】- Quiz2(Week 6)

【Machine Learning】【Andrew Ng】- Quiz2(Week 6)

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 classier 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 classier’s score (as a value from 0 to 1)?
答案:0.1581.
解析:
precision = 85/(85+890);
recall = 85/(85+15);

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?
A. When we are willing to include high order polynomial features of (such as x1^2,x2^2,x1x2,etc.).

B. We train a learning algorithm with a large number of parameters (that is able to learn/represent fairly complex functions).

C. The features contain sufficient information to predict accurately. (For example, one way to verify this is if a human expert on the domain can confidently predict y when given only x).

D. We train a learning algorithm with a small number of parameters (that is thus unlikely to overfit).

答案:BC。這兩個條件都很重要,容易忘記。

3、Suppose you have trained a logistic regression classier which is outputing h(x).
Currently, you predict 1 if h(x)>= threshold, and predict 0 if h(x) less than threshold, where currently the threshold is set to 0.5.
Suppose you increase the threshold to 0.9. Which of the following are true? Check all that apply.
A、The classifier is likely to now have lower precision.
B、The classifier is likely to now have lower recall.
C、The classifier is likely to have unchanged precision and recall, but lower accuracy.
D、The classifier is likely to have unchanged precision and recall, but
higher accuracy.
答案:B。我理解得precision就是預測準的概率,recall就是不漏掉的概率。所以閾值越高,越容易預測準,越confident,但是也越容易有漏網之魚。

4、Suppose you are working on a spam classier, 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.
A、If you always predict non-spam (output y=0), your classier will have a recall of 0%.
B、If you always predict spam (output y=1), your classier will have a recall of 0% and precision of 99%.
C、If you always predict spam (output y=1), your classier will have a recall of 100% and precision of 1%.
D、If you always predict non-spam (output y=0), your classier will have an accuracy of 99%.
答案:ACD
當全部預測為1時,如下:

/ actual class:1 actual class 0
predicted class:1 1% 99%
predicted class:0 0 0

accuracy = 1%
precision = 1%/(1%+99%) = 1%
recall = 1%/(1%+0) = 100%
當全部預測為0時,如下:

/ actual class:1 actual class 0
predicted class:1 0 0
predicted class:0 1% 99%

accuracy = 99%
precision = 0/(0+0) = 0%
recall = 0/(0+1%) = 0%

5、Which of the following statements are true? Check all that apply.
A、If your model is underfitting the training set, then obtaining more data is likely to help.
B、Using a very large training set makes it unlikely for model to overfit the training data.
C、It is a good idea to spend a lot of time collecting a large amount of data before building your first version of a learning algorithm.
D、After training a logistic regression classier, you must use 0.5 as your threshold for predicting whether an example is positive or negative.
E、On skewed datasets (e.g., when there are more positive examples than negative examples), accuracy is not a good measure of performance and you should instead use score based on the precision and recall.
答案:BE
A,錯誤,underfit主要是模型的問題,多點訓練集並不會很大改善效能
B,對啊,訓練集大了,模型自然很難滿足所有的訓練樣本,所以也更難overfit啦
C,錯誤,第一個模型簡單就好,不需要太多的資料,後面進行調整模型的時候需不需要更多的訓練樣本再看情況
D,錯誤,閾值取多少沒有一個固定的數值,看你需要的效能,一般看F1值,取最大值。
E,正確。

相關推薦

Coursera—Andrew Ng機器學習—Week 8 習題—聚類 和 降維

【1】無監督演算法 【2】聚類 【3】代價函式 【4】 【5】K的選擇 【6】降維 Answer:本來是 n 維,降維之後變成 k 維(k ≤ n) 【7】 【8】 Answer: 斜率-1 【9】   Answer: x 是一個向

Coursera—Andrew Ng機器學習—Week 10 習題—大規模機器學習

【1】大規模資料 【2】隨機梯度下降 【3】小批量梯度下降 【4】隨機梯度下降的收斂 Answer:BD A 錯誤。學習率太小,演算法容易很慢 B 正確。學習率小,效果更好 C 錯誤。應該是確定閾值吧 D 正確。曲線不下降,說明學習率選的太大  【5】線上學習

Coursera—Andrew Ng機器學習—課程筆記 Lecture 10—Advice for applying machine learning

Lecture 10—Advice for applying machine learning   10.1 如何除錯一個機器學習演算法? 有多種方案: 1、獲得更多訓練資料;2、嘗試更少特徵;3、嘗試更多特徵;4、嘗試新增多項式特徵;5、減小 λ;6、增大 λ 為了避免一個方案一個方

Coursera—Andrew Ng機器學習—課程筆記 Lecture 11—Machine Learning System Design

Lecture 11—Machine Learning System Design 11.1 垃圾郵件分類 本章中用一個實際例子: 垃圾郵件Spam的分類 來描述機器學習系統設計方法。首先來看兩封郵件,左邊是一封垃圾郵件Spam,右邊是一封非垃圾郵件Non-Spam:垃圾郵件有很多features。如果我

Coursera—Andrew Ng機器學習—課程筆記 Lecture 17—Large Scale Machine Learning 大規模機器學習

Lecture17 Large Scale Machine Learning大規模機器學習 17.1 大型資料集的學習 Learning With Large Datasets 如果有一個低方差的模型, 通常通過增加資料集的規模,可以獲得更好的結果。 但是如果資料集特別大,則首先應該檢查這麼大規模是否真

Machine LearningAndrew Ng- Quiz2(Week 6)

1、You are working on a spam classification system using regularized logistic regression. “Spam” is a positive class (y = 1) and “no

Machine LearningAndrew Ng- Quiz(Week 7)

1、Suppose you have trained an SVM classier with a Gaussian kernel, and it learned the following decision boundary on the training s

Machine LearningAndrew Ng- Quiz1(Week 8)

1、For which of the following tasks might K-means clustering be a suitable algorithm? Select all that apply. A. Given a database o

Andrew Ng 機器學習Exercise1——Linear Regression

1、單變數線性迴歸 在本部分練習中,您將使用一個變數實現線性迴歸,以預測食品卡車的利潤。假設你是一家連鎖餐廳的執行長,正在考慮在不同的城市開設一家新分店。這個連鎖店已經在不同的城市有了卡車,你可以從城市得到利潤和人口的資料。 您希望使用這些資料來幫助您選擇下一個要擴充套件到的城市。

Machine :Learning 樸素貝葉斯

1. 樸素貝葉斯: 條件概率在機器學習演算法的應用。理解這個演算法需要一點推導。不會編輯公式。。 核心就是 在已知訓練集的前提條件下,算出每個特徵的概率為該分類的概率, 然後套貝葉斯公式計算 預測集的所有分類概率,預測型別為概率最大的型別 from numpy import * def l

Machine Learning, Coursera機器學習Week6 偏斜資料集的處理

ML Week6: Handing Skewed Data 本節內容: 1. 查準率和召回率 2. F1F1 Score 偏斜類(skewed class)問題:資料集中每一類的資料量嚴重不均衡 如果資料集為偏斜類,分類正確率不是一個好的指標。

Machine Learning, Coursera機器學習Week7 核函式

Kernels 本節內容: 核函式(Kernel)是一類計算變數間相似度的函式,它可用於構造新的特徵變數,幫助SVM解決複雜的非線性分類問題。 相關機器學習概念: 相似度函式(Similarity Function) 高斯核函式(Gaussian Kernel

Machine Learning 線性迴歸

線性迴歸 我們可以通過測量損耗來衡量線路的適合程度。 線性迴歸的目標是最小化損失。 為了找到最佳擬合線,我們嘗試找到最小化損失的b值(截距)和m值(斜率)。 收斂是指引數在每次迭代時停止變化時的引數 學習率是指每次迭代時引數的變化程度。 我們可以

Andrew Ng《Class of 2017 Sloan Fellows presents》

I want to share with you what I think the major trends in AI. Because I guess the title of this

Coursera—Andrew Ng機器學習—彙總(課程筆記、測驗習題答案、程式設計作業原始碼)

一、Coursera 斯坦福機器學習課程,Andrew Ng Coursera連線不上,修改hosts檔案 機器學習工具Octave安裝(Win10環境) 課程地址和軟體下載  

Coursera—Andrew Ng機器學習—課程筆記 Lecture 12—Support Vector Machines 支援向量機

Lecture 12 支援向量機 Support Vector Machines 12.1 優化目標 Optimization Objective 支援向量機(Support Vector Machine) 是一個更加強大的演算法,廣泛應用於工業界和學術界。與邏輯迴歸和神經網路相比, SVM在學習複雜的非

Coursera—Andrew Ng機器學習—課程筆記 Lecture 14—Dimensionality Reduction 降維

Lecture 14 Dimensionality Reduction 降維 14.1 降維的動機一:資料壓縮 Data Compression 現在討論第二種無監督學習問題:降維。 降維的一方面作用是資料壓縮,允許我們使用較少的記憶體或磁碟空間,也加快演算法速度。 例子: 假設我們用兩個特徵描述一個物

Coursera—Andrew Ng機器學習—課程筆記 Lecture 15—Anomaly Detection異常檢測

Lecture 15 Anomaly Detection 異常檢測 15.1 異常檢測問題的動機 Problem Motivation 異常檢測(Anomaly detection)問題是機器學習演算法的一個常見應用。這種演算法雖然主要用於無監督學習問題,但從某些角度看,它又類似於一些監督學習問題。舉例:

Coursera—Andrew Ng機器學習—課程筆記 Lecture 16—Recommender Systems 推薦系統

Lecture 16 Recommender Systems 推薦系統 16.1 問題形式化 Problem Formulation 在機器學習領域,對於一些問題存在一些演算法, 能試圖自動地替你學習到一組優良的特徵。通過推薦系統(recommender systems),將領略一小部分特徵學習的思想。