Machine Learning 第八波编程作业(完)——Anomaly Detection and Recommender Systems

仅列出核心代码:

1.estimateGuassian.m

mu = mean(X)';
X2 = (X - ones(m, 1)*mu').^2;
sigma2 = mean(X2);

2.selectThreshold.m

cvPredictions = (pval < epsilon);
tp = sum((cvPredictions == 1) & (yval == 1));
fp = sum((cvPredictions == 1) & (yval == 0));
fn = sum((cvPredictions == 0) & (yval == 1));
prec = tp/(tp + fp);
rec = tp/(tp + fn);
F1 = 2*prec*rec/(prec + rec);

3.cofiCostFunc.m

X1 = (X*Theta'- Y).*R;
reg1 = (sum(sum(X.^2)) + sum(sum(Theta.^2)))*lambda/2;
J = sum(sum((X1).^2))/2 + reg1;

X_grad = X1*Theta + lambda*X;
Theta_grad = X1'*X + lambda*Theta;

课程地址:https://www.coursera.org/course/ml

 

posted on 2013-06-25 00:16  Andnot  阅读(536)  评论(0编辑  收藏  举报

导航