Coursera机器学习week9 编程作业

estimateGaussian.m

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

selectThreshold.m

predictions = (pval < epsilon);
fp = sum((predictions == 1) & (yval == 0));
fn = sum((predictions == 0) & (yval == 1));
tp = sum((predictions == 1) & (yval == 1));

prec = tp/(tp+fp);
rec = tp/(tp+fn);
    
F1 = 2 * prec * rec / (prec + rec);

cofiCostFunc.m

temp = (X*Theta').*R;
J = sum( sum( (temp - Y.*R).^2) )/2.0 + (lambda/2) * ( sum(sum( X.^2 )) + sum(sum( Theta.^2 )) );  
% J = sum( sum( (temp - Y.*R).^2) )/2.0 + (lambda/2) * ( sum(sum( X.^2 )) + sum(sum( Theta.^2 )) ) ;

X_grad = (temp - Y.*R) * Theta + lambda * X;
Theta_grad = (temp - Y.*R)' * X + lambda * Theta;

  

posted @ 2018-02-10 11:26  starry_sky  阅读(1035)  评论(0编辑  收藏  举报