[机器学习] 面试常见问题+解析汇总
機器學習面試題的分類
?
一 方差與偏差
-
偏差與方差分別是用于衡量一個模型泛化誤差的兩個方面;
- 模型的偏差,指的是模型預測的期望值與真實值之間的差;度量了學習算法的期望輸出與真實結果的偏離程度, 刻畫了算法的擬合能力,Bias 偏高表示預測函數與真實結果差異很大。
- 模型的方差,指的是模型預測的期望值與預測值之間的差平方和;則代表“同樣大小的不同的訓練數據集訓練出的模型”與“這些模型的期望輸出值”之間的差異。訓練集變化導致性能變化, Variance 偏高表示模型很不穩定
-
偏差用于描述模型的擬合能力
方差用于描述模型的穩定性
如何權衡偏差與方差?
- 偏差:度量學習算法的期望預測與真實結果的偏離程度,也叫擬合能力。
- 方差:度量了同樣大小的訓練集的變動所導致的學習性能的變化,即刻畫了數據擾動造成的影響。
?
- 隨著模型變復雜,Bias導致的error下降;
- 隨著模型變復雜,Variance導致的error上升;
- 隨著模型變復雜,error由下降到上升。
- 模型較簡單時,大的Bias,小的Variance,Underfitting!
- 模型過于復雜時,小的Bias,大的Variance,Overfitting!
最后談一下 K-fold Cross Validation 與權衡 Bais-Variance 之間的關系。這個理解其實很簡單,先看對于數據的劃分“
k-fold交叉驗證常用來確定不同類型的模型(線性、指數等)哪一種更好,為了減少數據劃分對模型評價的影響,最終選出來的模型類型(線性、指數等)是k次建模的誤差平均值最小的模型。
當k較大時,經過更多次數的平均可以學習得到更符合真實數據分布的模型,Bias就小了,但是這樣一來模型就更加擬合訓練數據集,再去測試集上預測的時候預測誤差的期望值就變大了,從而Variance就大了;
反之,k較小時模型不會過度擬合訓練數據,從而Bias較大,但是正因為沒有過度擬合訓練數據,Variance也較小。
過擬合原因
數據:數據不規范,數據量少,數據泄露,統計特征用到了未來的信息或者標簽信息
算法:算法過于復雜
解決:
1、將數據規范化,處理缺失值,增加數據量,采樣,添加噪聲數據
2、正則化,控制模型復雜程度,
3、early stoping,減少迭代次數,減少樹的深度,
4、學習率調大/小點、
5、融合幾個模型
二 如何處理數據中的缺失值
可以分為以下 2 種情況:
缺失值較多
- 直接舍棄該列特征,否則可能會帶來較大的噪聲,從而對結果造成不良影響。
缺失值較少
當缺失值較少(<10%)時,可以考慮對缺失值進行填充,以下是幾種常用的填充策略:用一個異常值填充(比如 0),將缺失值作為一個特征處理
data.fillna(0)
用均值|條件均值填充
如果數據是不平衡的,那么應該使用條件均值填充
所謂條件均值,指的是與缺失值所屬標簽相同的所有數據的均值
data.fillna(data.mean())
用相鄰數據填充???????
# 上一個數據填充 data_train.fillna(method='pad') # 下一個數據填充 data_train.fillna(method='bfill')用隨機森林等算法擬合???????
將數據分為有值和缺失值2份,對有值的數據采用隨機森林擬合,然后對有缺失值的數據進行預測,用預測的值來填充。
三 KNN和K-Means的區別 ?
More reading:?How is the k-nearest neighbor algorithm different from k-means clustering? (Quora)
K-Nearest Neighbors is a supervised classification algorithm, while k-means clustering?is an unsupervised clustering algorithm. While the mechanisms may seem similar at first, what this really means is that in order for K-Nearest Neighbors to work, you need labeled data you want to classify an unlabeled point into (thus the nearest neighbor part). K-means clustering requires only a set of unlabeled points and a threshold: the algorithm will take unlabeled points and gradually learn how to cluster them into groups by computing the mean of the distance between different points.
The critical difference here is that KNN needs labeled points and is thus supervised learning, while k-means doesn’t — and is thus unsupervised learning.
| KNN | K-Means |
| 目的是為了確定一個點的分類 | 目的是為了將一系列點集分成k類 |
| 1.KNN是分類算法 2.監督學習,分類目標事先已知 3.喂給它的數據集是帶label的數據,已經是完全正確的數據 | 1.K-Means是聚類算法 2.非監督學習 3.喂給它的數據集是無label的數據,是雜亂無章的,經過聚類后才變得有點順序,先無序,后有序 |
| 沒有明顯的前期訓練過程,屬于memory-based learning | 有明顯的前期訓練過程 |
| K的含義:來了一個樣本x,要給它分類,即求出它的y,就從數據集中,在x附近找離它最近的K個數據點,這K個數據點,類別c占的個數最多,就把x的label設為c | K的含義:K是人工固定好的數字,假設數據集合可以分為K個簇,由于是依靠人工定好,需要一點先驗知識 |
| K值確定后每次結果固定 | K值確定后每次結果可能不同,從 n個數據對象任意選擇 k 個對象作為初始聚類中心,隨機性對結果影響較大 |
| ? | ? |
| 相似點:都包含這樣的過程,給定一個點,在數據集中找離它最近的點。即二者都用到了NN(Nears Neighbor)算法,一般用KD樹來實現NN。 ? | |
理解準確率(accuracy)、精度(precision)、查全率(recall)、F1
More reading:?Precision and recall (Wikipedia)
Recall is also known as the true positive rate: the amount of positives your model claims compared to the actual number of positives there are throughout the data. Precision is also known as the positive predictive value, and it is a measure of the amount of accurate positives your model claims compared to the number of positives it actually claims. It can be easier to think of recall and precision in the context of a case where you’ve predicted?that there were 10 apples and 5 oranges in a case of 10 apples. You’d have perfect recall (there are actually 10 apples, and you predicted there would be 10) but 66.7% precision because out of the 15 events you predicted, only 10 (the apples) are correct.
- 預測值為正例,記為P(Positive)
- 預測值為反例,記為N(Negative)
- 預測值與真實值相同,記為T(True)
- 預測值與真實值相反,記為F(False)
(1) 真陽性(True Positive,TP):檢測有結節,且實際有結節;正確肯定的匹配數目;
(2) 假陽性(False Positive,FP):檢測有結節,但實際無結節;誤報,給出的匹配是不正確的;
(3) 真陰性(True Negative,TN):檢測無結節,且實際無結節;正確拒絕的非匹配數目;
(4) 假陰性(False Negative,FN):檢測無結節,但實際有結節;漏報,沒有正確找到的匹配的數目。
?
反映的是分類器準確識別真陽性和假陰性的比率。看起來似乎這個指標已經能反映一個分類器的性能了,但我們應當想起一個很重的前提:這個ACC是只針對目前輸入的這一組數據做出的判斷。這就很容易因為數據偏斜造成模型的“測不準”。
準確率P、召回率R、F1 值
- 準確率 (Accuracy):(TP+TN)/(TP+TN+FP+FN) ?? 通俗地講, (預測正確的樣本數)/(總樣本數)
- 精度 ? ?(Precision 查準率):P=TP/(TP+FP)。? 通俗地講,就是預測正確的正例數據占預測為正例數據的比例。
- 召回率(Recall?????? 查全率):??? R=TP/(TP+FN)。? 通俗地講,就是預測為正例的數據占實際為正例數據的比例
- F1值(F score):
分類閾值對Precision/Recall的影響
做二值分類時,我們認為,若h(x)>=0.5,則predict=1;若h(x)<0.5,則predict=0。這里0.5就是分類閾值。
增加閾值,我們會對預測值更有信心,即增加了查準率。但這樣會降低查全率。(High Precision, Low Recall)
減小閾值,則模型放過的真例就變少,查全率就增加。(Low Precision, High Recall)
?
五 解釋下ROC 和AUC ?
More reading:?Receiver operating characteristic (Wikipedia)
The ROC curve is a graphical representation of the contrast between true positive rates and the false positive rate at various thresholds. It’s often used as a proxy for the trade-off between the sensitivity of the model (true positives) vs the fall-out or the probability it will trigger a false alarm (false positives).
ROC曲線是用來驗證一個分類器(二分)模型的性能的。其工作原理是,給出一個模型,輸入已知正負類的一組數據,并通過對比模型對該組數據進行的預測,衡量這個模型的性能。
注意,“測試數據”的正負類是已知的,我們需要的是判斷模型預測數據的陽性、陰性是否符合“測試數據”的事實。
?
>ROC曲線是怎么畫的呢?
?
AUC(Area Under Curve),是對ROC曲線的量化指標。
一個合適的分類器,要求做到TPR較高而FPR較小,體現在曲線上,就是在相同的FPR時,TPR越大的越好:
如上圖中,紅線對應的分類器的性能就好過藍線對應的分類器。
但對于人類來說,通過人眼識別自然很簡單。但對于計算機呢?而且,某些情況下,ROC曲線并不一定是完全光滑的(由于閾值取值的問題等),有可能某一個時刻紅線超過了藍線而另一個時刻藍線超過了紅線,這就很難進行判斷到底哪個分類器性能好。
所以我們用AUC進行評價。AUC的值,等于曲線與FPR軸線形成的面積。AUC的值越大越好,其取值范圍為(0.5,1)
六 什么是貝葉斯定理?? How is it useful in a machine learning context?
More reading:?An Intuitive (and Short) Explanation of Bayes’ Theorem (BetterExplained)
Bayes’ Theorem gives you the posterior probability of an event given what is known as prior knowledge.
Mathematically, it’s expressed as the true positive rate of a condition sample divided by the sum?of the false positive rate of the population and the true positive rate of a condition. Say you had a 60% chance of actually having the flu after a flu test, but out of people who had the flu, the test will be false 50% of the time, and the overall population only has a 5% chance of having the flu. Would you actually have a 60% chance of having the flu after having a positive test?
Bayes’ Theorem says no. It says that you have a (.6 * 0.05) (True Positive Rate of a Condition Sample) / (.6*0.05)(True Positive Rate of a Condition Sample) + (.5*0.95) (False Positive Rate of a Population) ?= 0.0594 or 5.94% chance of getting a flu.
Bayes’ Theorem is the basis behind a branch of machine learning that most notably includes the Naive Bayes classifier. That’s something important to consider when you’re faced with machine learning interview questions.
七 為什么樸素貝葉斯如此“樸素”?
More reading:?Why is “naive Bayes” naive? (Quora)
因為它假定所有的特征在數據集中的作用是同樣重要和獨立的。正如我們所知,這個假設在現實世界中是很不真實的,因此,說樸素貝葉斯真的很“樸素”。
naive(樸素)是指的對于模型中各個 feature(特征) 有強獨立性的假設,并未將 feature 間的相關性納入考慮中。
樸素貝葉斯分類器一個比較著名的應用是用于對垃圾郵件分類,通常用文字特征來識別垃圾郵件,是文本分類中比較常用的一種方法。
八 什么是正則化, 為什么要正則化?? 請給出一些正則化常用方法。
More reading:?What is the difference between L1 and L2 regularization? (Quora)
從貝葉斯的角度來看,加入正則項相當于加入了一種先驗。即當訓練一個模型時,僅依靠當前的訓練數據集是不夠的,為了實現更好的泛化能力,往往需要加入先驗項。
L1范數相當于加入了一個Laplacean先驗(拉普拉斯分布); L2范數相當于加入了一個Gaussian先驗。
九 數據規范化是什么? 為什么需要對數據進行規范化?
數據規范化在預處理階段尤為重要,它可以將數值縮放到特定的范圍,以在反向傳播時獲得更好的收斂性。一般而言,規范化就是讓每一個數據點減去它們的均值,并除以標準差。
如果不這樣處理,一些(數量級較大的)特征值在代價函數中的權重就會更大(如果大數量級特征值改變1%,代價函數的變化就會很大,但小數量級的特征值改變1%產生的影響則微乎其微)。規范化使得所有特征值具有相同的權重。
1)歸一化后加快了梯度下降求最優解的速度
如下圖所示,藍色的圈圈圖代表的是兩個特征的等高線。其中左圖兩個特征X1和X2的區間相差非常大,X1區間是[0,2000],X2區間是[1,5],其所形成的等高線非常尖。當使用梯度下降法尋求最優解時,很有可能走“之字型”路線(垂直等高線走),從而導致需要迭代很多次才能收斂;? ?
? 而右圖對兩個原始特征進行了歸一化,其對應的等高線顯得很圓,在梯度下降進行求解時能較快的收斂。? ? ? 因此如果機器學習模型使用梯度下降法求最優解時,歸一化往往非常有必要,否則很難收斂甚至不能收斂。
?
2)歸一化有可能提高精度。
?一些分類器需要計算樣本之間的距離(如歐氏距離),例如KNN。如果一個特征值域范圍非常大,那么距離計算就主要取決于這個特征,從而與實際情況相悖(比如這時實際情況是值域范圍小的特征更重要)。
3)哪些機器學習算法不需要做歸一化處理?
概率模型不需要歸一化,因為它們不關心變量的值,而是關心變量的分布和變量之間的條件概率,如決策樹、RF。而像Adaboost、GBDT、XGBoost、SVM、LR、KNN、KMeans之類的最優化問題就需要歸一化。
1)線性歸一化
? ? ? 這種歸一化方法比較適用在數值比較集中的情況。這種方法有個缺陷,如果max和min不穩定,很容易使得歸一化結果不穩定,使得后續使用效果也不穩定。實際使用中可以用經驗常量值來替代max和min。
2)標準差標準化
經過處理的數據符合標準正態分布,即均值為0,標準差為1,其轉化函數為:
其中μ為所有樣本數據的均值,σ為所有樣本數據的標準差。
3)非線性歸一化
? ? ?經常用在數據分化比較大的場景,有些數值很大,有些很小。通過一些數學函數,將原始值進行映射。該方法包括 log、指數,正切等。需要根據數據分布的情況,決定非線性函數的曲線,比如log(V, 2)還是log(V, 10)等。
十 What’s the difference between Type I and Type II error?
More reading:?Type I and type II errors (Wikipedia)
Don’t think that this is a trick question! Many machine learning interview questions will be an attempt to?lob basic questions at you just to make sure you’re on top of your game and you’ve prepared all of your bases.
Type I error is a false positive, while Type II error is a false negative. Briefly stated, Type I error means claiming something has happened when it hasn’t, while Type II error means that you claim nothing is happening when in fact something is.
A clever way to think about this is to think of Type I error as telling a man he is pregnant, while Type II error means you tell a pregnant woman she isn’t carrying a baby.
Type I error 是指統計學中的一類錯誤,意思是本來是錯誤的結論卻被接受了。Type II error 是指統計學中的二類錯誤,也就是本來是正確的錯誤卻被拒絕了。簡而言之,就是存偽和棄真。
第一類錯誤是指:原假設事實上正確,可是檢驗統計量的觀測值卻落入拒絕域, 因而否定了本來正確的假設.這是棄真的錯誤, 為了降低第一類錯誤的概率,就要盡可能的做接受的推斷,隨之帶來的就是可能把假的也當成真的接受了,這就導致納偽錯誤的增加,即增加第二類錯誤發生的概率. 原假設事實上不正確,而檢驗統計量的觀測值卻落入了不能拒絕域,因而沒有否定本來不正確的原假設,這是取偽的錯誤.
這樣本容量固定的前提下,兩類錯誤的概率不能同時減少.為了同時減少兩類錯誤的概率就得增加樣本容量.
十一 傅里葉變換?
More reading: Fourier transform (Wikipedia)
A Fourier transform is a generic method to decompose generic functions into a superposition of symmetric functions. Or as this more intuitive tutorial?puts it, given a smoothie, it’s how we find the recipe. The Fourier transform finds the set of cycle speeds, amplitudes and phases to match any time signal. A Fourier transform converts a signal from time to frequency domain — it’s a very common way to extract features from audio signals or other time series such as sensor data.
圖像或聲音的數字信號通常在時域上是連續的不具有稀疏性,但經過傅里葉變換、余弦變換、小波變換等處理手段后會轉換為頻域上的稀疏信號
十二? 概率 and 和似然?
More reading: What is the difference between “likelihood” and “probability”? (Cross Validated)
概率(probability)和似然(likelihood),都是指可能性,都可以被稱為概率,但在統計應用中有所區別。
?? 概率是給定某一參數值,求某一結果的可能性。例如,拋一枚勻質硬幣,拋10次,6次正面向上的可能性多大?
?? 似然是給定某一結果,求某一參數值的可能性。例如,拋一枚硬幣,拋10次,結果是6次正面向上,其是勻質的可能性多大?
十三 生成模型和判別模型區別?
More reading:?What is the difference between a Generative and Discriminative Algorithm? (Stack Overflow)
A generative model will learn categories of data while a discriminative model will simply learn the distinction between different categories of data. Discriminative models will generally outperform generative models on classification tasks.
判別方法:由數據直接學習決策函數 Y = f(X),或者由條件分布概率 P(Y|X)作為預測模型,即判別模型。
生成方法:由數據學習聯合概率密度分布函數 P(X,Y),然后求出條件概率分布P(Y|X)作為預測的模型,即生成模型。
由生成模型可以得到判別模型,但由判別模型得不到生成模型。
常見的判別模型有:K近鄰、SVM、決策樹、感知機、線性判別分析(LDA)、線性回歸、傳統的神經網絡、邏輯斯蒂回歸、boosting、條件隨機場
常見的生成模型有:樸素貝葉斯、隱馬爾可夫模型、高斯混合模型、文檔主題生成模型(LDA)、限制玻爾茲曼機
十四 線性分類器與非線性分類器的區別以及優劣?
如果模型是參數的線性函數,并且存在線性分類面,那么就是線性分類器,否則不是。
常見的線性分類器有:LR,貝葉斯分類,單層感知機、線性回歸。
常見的非線性分類器:決策樹、RF、GBDT、多層感知機。
SVM兩種都有(看線性核還是高斯核)。
線性分類器速度快、編程方便,但是可能擬合效果不會很好。
非線性分類器編程復雜,但是效果擬合能力強。
十五 What cross-validation technique would you use on a time series dataset?
More reading:?Using k-fold cross-validation for time-series model selection (CrossValidated)
Instead of using standard k-folds cross-validation, you have to pay attention to the fact that a time series is not randomly distributed data — it is inherently ordered by chronological order. If a pattern emerges in later time periods for example, your model may still pick up on it even if that effect doesn’t hold in earlier years!
You’ll want to do something like forward chaining where you’ll be able to model on past data then look at forward-facing data.
- fold 1 : training [1], test [2]
- fold 2 : training [1 2], test [3]
- fold 3 : training [1 2 3], test [4]
- fold 4 : training [1 2 3 4], test [5]
- fold 5 : training [1 2 3 4 5], test [6]
十六 什么是決策樹剪枝?
More reading:?Pruning (decision trees)
決策樹對訓練屬于有很好的分類能力,但是對于未知的測試集未必有好的分類能力,泛化能力弱,即可能發生過擬合現象。 決策樹是充分考慮了所有的數據點而生成的復雜樹,有可能出現過擬合的情況,決策樹越復雜,過擬合的程度會越高。為防止過擬合,我們需要進行剪枝。?? 剪枝修剪分裂前后分類誤差相差不大的子樹,能夠降低決策樹的復雜度,降低過擬合出現的概率
Pruning can happen bottom-up and top-down, with approaches such as reduced error pruning and cost complexity pruning.
Reduced error pruning is perhaps the simplest version: replace each node. If it doesn’t decrease predictive accuracy, keep it pruned. While simple, this heuristic actually comes pretty close to an approach that would optimize for maximum accuracy.
剪枝分為預剪枝和后剪枝:
預剪枝:
(1)每一個結點所包含的最小樣本數目,例如10,則該結點總樣本數小于10時,則不再分;
(2)指定樹的高度或者深度,例如樹的最大深度為4;
(3)指定結點的熵小于某個值,不再劃分。
?后剪枝:
總體思路:由完全樹T0開始,剪枝部分結點得到T1,再次剪枝部分結點得到T2...直到剩下樹根的樹Tk;在驗證數據集上對這k個樹分別評價,選擇損失函數最小的樹Ta。
十七 Which is more important to you– model accuracy, or model performance?
More reading:?Accuracy paradox (Wikipedia)
This question tests your grasp of the nuances of machine learning model performance! Machine learning interview questions often look towards the details. There are models with higher accuracy that can perform worse in predictive power — how does that make sense?
Well, it has everything to do with how model accuracy is only a subset of model performance, and at that, a sometimes misleading one. For example, if you wanted to detect fraud in a massive dataset with a sample of millions, a more accurate model would most likely predict no fraud at all if only a vast minority of cases were fraud. However, this would be useless for a predictive model — a model designed to find fraud that asserted there was no fraud at all! Questions like this help you demonstrate that you understand model accuracy?isn’t the be-all and end-all of model performance.
十八 如何處理數據集中缺失或損壞的數據?
你可以在數據集中找到缺失/損壞的數據,并刪除它所在的行或列,或是用其他值代替之。
Pandas中有兩個非常有效的函數:isnull()和dropna(),這兩個函數可以幫你找到有缺失/損壞數據的行,并刪除對應值。如果要用占位符(比如0)填充這些無效值,你可以使用fillna()函數。
十九 如何處理不平衡數據集?
More reading: 8 Tactics to Combat Imbalanced Classes in Your Machine Learning Dataset (Machine Learning Mastery)
An imbalanced dataset is when you have, for example, a classification test and 90% of the data is in one class. That leads to problems: an accuracy of 90% can be skewed if you have no predictive power on the other category of data! Here are a few tactics to get over the hump:
1- Collect more data to even the imbalances in the dataset.
2- Resample the dataset to correct for imbalances.
3- Try a different algorithm altogether on your dataset.
What’s important here is that you have a keen sense for what damage an unbalanced dataset can cause, and how to balance that.
二十 如何開展探索性數據分析(EDA)?
EDA的目的是在應用預測模型之前,了解數據的信息,獲得對數據的直觀感受。總的來說,開展探索性數據分析一般采取由粗到精的方法。
如何開展數據分析
(1)首先獲取一些高層次、全局性的直觀感受。檢查一下不平衡的類,查看每一類的均值和方差。看看第一行,了解數據大致內容。運行pandas中的http://df.info()函數,看看哪些是連續變量、分類變量,并查看變量的數據類型(整型、浮點型、字符串)。然后刪掉一些在分析、預測中不需要的列,這些列中的很多行數值都相同(提供的信息也相同),或者存在很多缺失值。我們也可以用某一行/列的眾數或中值填充該行/列中的缺失值。
(2)可以做一些基本的可視化操作。從相對高層次、全局性的角度開始,比如繪制分類特征關于類別的條形圖,繪制最終類別的條形圖,探究一下最“常用”的特征,對獨立變量進行可視化以獲得一些認知和靈感等。
(3)可以展開更具體的探索。比如同時對兩三個特征進行可視化,看看它們相互有何聯系。也可以做主成分分析,來確定哪些特征中包含的信息最多。類似地,還可以將一些特征分組,以觀察組間聯系。
比如可以考察一下,取A = B = 0時,不同的類會有什么表現?取A = 1、B = 0時呢?還要比較一下不同特征的影響,比方說特征A可以取“男性”或“女性”,則可以畫出特征A與旅客艙位的關系圖,判斷男性和女性選在艙位選擇上是否有差異。
除了條形圖、散點圖或是其他基本圖表,也可以畫出PDF(概率分布函數)或CDF(累計分布函數)、使用重疊繪圖方法等。還可以考察一下統計特性,比如分布、p值等。最后就該建立機器學習模型了。
從簡單的模型開始,比如樸素貝葉斯、線性回歸等。如果上述模型效果不理想,或是數據高度非線性,則考慮使用多項式回歸、決策樹或支持向量機。EDA可以挑選出重要的特征。如果數據量很大,可以使用神經網絡。別忘了檢查ROC曲線(感受性曲線)、準確率和召回率。
?
二十一 請解釋 降維,以及使用場合和優勢? 解釋一下什么是PCA?
降維是一種通過分析出主變量來減少特征變量的過程,其中主變量通常就是重要的特征。一個特征變量的重要性取決于它對數據信息的解釋程度,以及你所采用的方法。至于如何選取方法,主要靠不斷摸索,以及你自己的偏好。通常大家會從線性方法開始,如果結果欠缺擬合性,則考慮嘗試非線性的方法。
數據降維的優勢
(1)節省存儲空間;
(2)節省計算時間(比如應用于機器學習算法時);
(3)去除冗余特征變量,正如同時以平方米和平方英里存儲地區面積沒有任何意義(甚至可能是收集數據時出現錯誤);
(4)將數據降維到二維或三維后,我們或許可以畫圖,將數據可視化,以觀察數據具有的模式,獲得對數據的直觀感受;
(5)特征變量過多或模型過于復雜可能導致模型過擬合。
PCA(principal Component Analysis),即主成分分析方法,是一種使用最廣泛的數據壓縮算法。在PCA中,數據從原來的坐標系轉換到新的坐標系,由數據本身決定。轉換坐標系時,以方差最大的方向作為坐標軸方向,因為數據的最大方差給出了數據的最重要的信息。第一個新坐標軸選擇的是原始數據中方差最大的方法,第二個新坐標軸選擇的是與第一個新坐標軸正交且方差次大的方向。重復該過程,重復次數為原始數據的特征維數。
通過這種方式獲得的新的坐標系,我們發現,大部分方差都包含在前面幾個坐標軸中,后面的坐標軸所含的方差幾乎為0,。于是,我們可以忽略余下的坐標軸,只保留前面的幾個含有絕不部分方差的坐標軸。事實上,這樣也就相當于只保留包含絕大部分方差的維度特征,而忽略包含方差幾乎為0的特征維度,也就實現了對數據特征的降維處理。
二十二 回歸(regression)與分類(classification)的區別?
More reading:?Regression vs Classification (Math StackExchange)
分類問題是指,給定一個新的模式,根據訓練集推斷它所對應的類別(如:+1,-1),是一種定性輸出,也叫離散變量預測;
回歸問題是指,給定一個新的模式,根據訓練集推斷它所對應的輸出值(實數)是多少,是一種定量輸出,也叫連續變量預測。
Logistic Regression 和 Linear Regression:
- Linear Regression:? 輸出一個標量 wx+b,這個值是連續值,所以可以用來處理回歸問題。
- Logistic Regression:把上面的 wx+b 通過 sigmoid函數映射到(0,1)上,并劃分一個閾值,大于閾值的分為一類,小于等于分為另一類,可以用來處理二分類問題。
- 更進一步:對于N分類問題,則是先得到N組w值不同的 wx+b,然后歸一化,比如用 softmax函數,最后變成N個類上的概率,可以處理多分類問題。
- ?
二十三? Name an example where ensemble techniques?might be useful.
More reading:?Ensemble learning (Wikipedia)
Ensemble techniques use a combination of learning algorithms to optimize better predictive performance. They typically reduce overfitting in models and make the model more robust (unlikely to be influenced by small changes in the training data).?
You could list some examples of ensemble methods, from bagging to boosting to a “bucket of models” method and demonstrate how they could increase predictive power.
二十四 如果確定模型是否過擬合overfitting?
More reading:?How can I avoid overfitting? (Quora)
overfittingt是這樣一種現象:一個假設在訓練數據上能夠獲得比其他假設更好的擬合,但是在訓練數據外的數據集上卻不能很好的擬合數據。此時我們就叫這個假設出現了overfitting的現象。出現這種現象的主要原因是訓練數據中存在噪音或者訓練數據太少。
3種方法避免過擬合
1- Keep the model simpler: reduce variance by taking into account fewer variables and parameters, thereby removing some of the noise in the training data.
2- 增加數據量(可以通過交叉驗證實現)such as k-folds cross-validation.
3- Use regularization techniques such as LASSO that penalize certain model parameters 在對模型的目標函數(objective function)或代價函數(cost function)加上正則項
Ps: Dropout,應用在深度學習中,例如:CNN。防止模型過擬合,可以提高模型泛化能力。
二十五 What evaluation approaches would you work to gauge the effectiveness of a machine learning model?
More reading: How to Evaluate Machine Learning Algorithms (Machine Learning Mastery)
You would first split the dataset into training and test sets, or perhaps use cross-validation techniques to further segment the dataset into composite sets of training and test sets within the data. You should then implement a choice selection of performance metrics: here is a fairly comprehensive list. You could use measures such as the F1 score, the accuracy, and the confusion matrix. What’s important here is to demonstrate that you understand the nuances of how a model is measured and how to choose the right performance measures for the right situations.
二十六 如果評估一個邏輯回歸模型?
More reading:?Evaluating a logistic regression (CrossValidated)
A subsection of the question above. You have to demonstrate an understanding of what the typical goals of a logistic regression are (classification, prediction etc.) and bring up a few examples and use cases.
二十七 什么是“核機制”,它有什么優勢?
More reading:?Kernel method (Wikipedia)
The Kernel trick involves kernel functions that can enable in higher-dimension spaces without explicitly calculating the coordinates of points within that dimension: instead, kernel functions compute the inner products between the images of all pairs of data in a feature space.
This allows them the very useful attribute of calculating the coordinates of higher dimensions while being computationally cheaper than the explicit calculation of said coordinates.?Many algorithms can be expressed in terms of inner products. Using the kernel trick enables us effectively run ?algorithms in a high-dimensional space with lower-dimensional data.
核機制:更高維空間內積的快速計算。也就是說,核機制的本質是計算內積(只不過這里參與內積運算的兩點屬于更高維的空間)。
如果數據在當前空間中不是線性可分的,則需做transform,將數據變換到更高的維度空間中。
也就是:Kernel = transform + inner product
Kernel機制的必要性和有效性可通過對比傳統的高維空間計算內積的方法顯現。
傳統的方法要分兩步,
- step1: 先從X空間升維到Z空間?
一般情況下,Z空間具有更高的維度。如果升維到無窮維空間,計算量更是難以忍受。
- step2: 再在Z空間里計算內積
核方法:
?
也就是說,K(x1,x2)計算得到的結果就是原始數據空間里的兩點先升維?(x)再進行內積?(x1)T?(x2)的結果,不必通過顯式的升維變換,也即是說,K(?)本身內嵌(embedded)了一種升維變換。兩步變一步,形式更為簡潔。
?
?
What’s your favorite algorithm, and can you explain it to me in less than a minute?
This type of question tests your understanding of how to communicate complex and technical nuances with poise and the ability to summarize quickly and efficiently. Make sure you have a choice and make sure you can explain different algorithms so simply and effectively that a five-year-old could grasp the basics!
為什么對圖像使用卷積而不只是FC層?
這個問題比較有趣,因為提出這個問題的公司并不多。但不排除一些公司會提出這個問題,如果面試時遇見,你可以分為兩方面回答這些問題。
卷積可以保存、編碼、使用圖像的空間信息。只用FC層的話可能就沒有相關空間信息了。
卷積神經網絡(CNN)某種程度上本身具有平移不變性,因為每個卷積核都充當了它自己的濾波器/特征監測器。
CNN具有平移不變性
上文解釋過,每個卷積核都充當了它自己的濾波器/特征監測器。假設你正在進行目標檢測,這個目標處于圖片的何處并不重要,因為我們要以滑動窗口的方式,將卷積應用于整個圖像。
為什么用CNN分類需要進行最大池化?
這也是屬于計算機視覺領域的一個問題。CNN中的最大池化可以減少計算量,因為特征圖在池化后將會變小。與此同時,因為采取了最大池化,并不會喪失太多圖像的語義信息。還有一個理論認為,最大池化有利于使CNN具有更好的平移不變性。關于這個問題,可以看一下吳恩達講解最大池化優點的視頻。
視頻鏈接:https://www.coursera.org/learn/convolutional-neural-networks/lecture/hELHk/pooling-layers
為什么用CNN分割時通常需要編碼-解碼結構?
CNN編碼器可以看作是特征提取網絡,解碼器則利用它提供的信息,“解碼”特征并放大到原始大小,以此預測圖像片段
為什么要使用許多小卷積核(如3*3的卷積核),而非少量大卷積核?
這篇VGGNet的論文中有很詳細的解釋。
使用小卷積核有兩個原因:
首先,同少數大卷積核一樣,更多小卷積核也可以得到相同的感受野和空間背景,而且用小卷積核需要的參數更少、計算量更小。
其次,使用小卷積核需要更多過濾器,這意味會使用更多的激活函數,因此你的CNN可以得到更具特異性的映射函數。
論文鏈接:https://arxiv.org/pdf/1409.1556.pdf
?
?
data-science-and-machine-learning-interview-questions
BAT機器學習面試1000題系列(一)
BAT機器學習面試1000題系列(二)
總結
以上是生活随笔為你收集整理的[机器学习] 面试常见问题+解析汇总的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: A Complete Machine L
- 下一篇: 中式恐怖游戏《转厝》Steam 页面上线