仅列出核心代码:
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