機器學習課堂筆記(十五)
<matlab>
% Find closest cluster members
idx = findClosestCentroids(X, centroids)
% Essentially, now we have represented the image X as in terms of
% the indices in idx.
% We can now recover the image from the indices (idx) by mapping
% each pixel (specified by it's index in idx) to the centroid value
X_recovered = centroids(idx,:);
% Reshape the recovered image into proper dimensions
X_recovered = reshape(X_recovered, img_size(1), img_size(2), 3);
<matlab>
調用
idx=findClosestCentroids(X, centroids)
得到 size(X,1)×1 的矩陣
調用
X_recovered = centroids(idx,:)
得到 size(X,1)×size(X,2) 的矩陣
<matlab>
% Instructions: Compute the projection of the data using only the
% top K eigenvectors in U (first K columns).
% For the i-th example X(i,:), the projection on to the k-th
% eigenvector is given as follows:
% x = X(i, :)';
% projection_k = x' * U(:, k);
<matlab>
調用
x = X(i, :)';
得到 size(X,2)×1 的列向量
調用
projection_k = x' * U(:, k);
得到 1×1 的值

根據樣本值計算 μ 和 σ
每個特征值服從不同的高斯分布
設計一種評估算法性能的方法讓選擇特征更容易
訓練樣本:交叉驗證集:測試集=6:2:2
對于偏斜的資料集:
1、計算真陽性,假陽性,假陰性,真陰性的值
2、計算查準率和召回率
3、計算 F1 積分
使用交叉驗證集選擇 σ ,然後使用測試集評估算法的性能
對于異常檢測:如果異常的種類很多的話,少量的正樣本難以學習到所有的異常。未來的異常可能和以前的異常完全不同
對于監督學習:擁有足夠的正樣本,未來的正樣本和訓練集中的正樣本相似
當擁有大量的正樣本和負樣本時,異常檢測也可以使用監督學習的算法
使用
hist(x_i)
檢視 xi 的分布
變換 xi 使其滿足高斯分布
尋找算法沒能标記的異常點,以此啟發創造新的特征變量,進而使其與正常點區分
Σ(1,1) 改變 x1 下降速度
Σ(2,2) 改變 x2 下降速度
Σ(1,2) 和 Σ(2,1) 改變 x1 和 x2 的相關性
多元分布的中心值為 (μ(1),μ(2))
根據樣本值計算 μ 和 Σ
原來的模型是多元高斯模型的一個特例
在m>10n的情況下,使用多元高斯模型能省去手動創造參數來捕捉異常的工作
如果m>n的情況下 Σ 任然不可逆,檢查備援特征變量