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;

I thought there was a problem with these equations because the region of highest probability was not displayed as a red ellipse in the PDF plot.

After debugging, I found that the center color of the contour plot for the Gaussian distribution is yellow, which is nearly invisible on non-Retina screens. 😂😂😂

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;

Translated by gpt-3.5-turbo