wk8 Anomaly Detection and Recommender Systems
最近正在学习MOOC上的经典课程:Machine learning (by Andrew Ng), 具体课程链接:MACHINE LEARNING
根据进度将作业的关键代码部分贴上,仅供交流与讨论。
- estimateGaussian
mu=sum(X)/m;
mu1=mu(ones(m,1),:);
sigma2=sum((X-mu1 ).^2)/m;
- selectThreshold
pred=(pval<epsilon);
tp=sum(yval==1&pred==1);
fp=sum(yval==0&pred==1);
fn=sum(yval==1&pred==0);
prec=tp/(tp+fp);
rec=tp/(tp+fn);
F1=2*prec*rec/(prec+rec);
- cofiCostFunc
h=X*Theta'-Y;
h1=h.*R;
J=(sum(sum(h1.^2)))/2+ lambda*(sum(sum(X.^2)))/2+lambda*(sum(sum(Theta.^2)))/2;
X_grad= h1*Theta+lambda*X;
Theta_grad= h1' *X+lambda*Theta;
——转载请注明出处