Anomaly Detection & Recommender Systems

Anomaly Detection

1.1 Gaussian distribution

1.2 Estimating parameters for a Gaussian

$$\mu {i} = \dfrac {1}{m}\sum{j=1}^{m}x _{i}^{(j)}$$

$$\sigma {i}^{2} = \dfrac{1}{m}\sum{j=1}^{m}(x _{i}^{(j)} - \mu _{i})^2$$

1
2
mu = sum(X)/m;
sigma2 = sum((X-mu).^2)/m;

我以为这些方程出了问题,因为概率最高的区域没有显示为 pdf 游的红色椭圆。

调试了一下,我发现高斯分布等值线的中心颜色是黄色的,在无 Retina 屏幕上几乎看不到。 😂😂😂

1.3 Selecting the threshold, ε



1
2
3
4
5
6
7
8
9
p = (pval < epsilon);
tp = sum((p == 1) & (yval == 1));
fp = sum((p == 1) & (yval == 0));
fn = sum((p == 0) & (yval == 1));

prec = tp/(tp+fp);
rec = tp/(tp+fn);

F1 = 2*prec*rec/(prec+rec);

Recommender Systems

2.1 Movie ratings dataset

2.2.1 Collaborative filtering cost function

1
2
tmp = X*Theta' .* R - Y;
J = sum(sum(tmp.^2))/2;

2.2.2 Collaborative filtering gradient

1
2
X_grad = tmp*Theta;
Theta_grad = tmp'*X;

2.2.3 Regularized cost function

1
J = J + lambda/2*(sum(sum(Theta.^2))) + lambda/2*(sum(sum(X.^2)));

2.2.4 Regularized gradient


1
2
X_grad = X_grad + lambda*X;
Theta_grad = Theta_grad + lambda*Theta;