Coursera机器学习week6 编程作业

Posted starry

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Coursera机器学习week6 编程作业相关的知识,希望对你有一定的参考价值。

linearRegCostFunction.m

J = 1/(2*m)*sum((X*theta-y).^2)+lambda/(2*m)*(sum(theta.^2)-theta(1).^2);

grad = 1/m*X‘*(X*theta-y)+lambda/m*theta;
grad(1) = grad(1) -lambda/m*theta(1)

learningCurve.m

for i = 1:m
	theta = trainLinearReg(X(1:i,:), y(1:i,:), lambda);
	error_train(i) = linearRegCostFunction(X(1:i,:), y(1:i,:), theta, 0); 
	error_val(i) = linearRegCostFunction(Xval, yval, theta, 0);
end

validationCurve.m

for i = 1 : length(lambda_vec)
	lambda = lambda_vec(i);
	theta = trainLinearReg(X, y, lambda);
	error_train(i) = linearRegCostFunction(X, y, theta, 0);
	error_val(i) = linearRegCostFunction(Xval, yval, theta, 0)
end

  

以上是关于Coursera机器学习week6 编程作业的主要内容,如果未能解决你的问题,请参考以下文章

Coursera机器学习week6 单元测试

吴恩达-coursera-机器学习-week6

机器学习- 吴恩达Andrew Ng Week6 知识总结 Machine Learning System Design

机器学习- 吴恩达Andrew Ng Week6 Regularized Linear Regression and Bias/Variance知识总结

机器学习- 吴恩达Andrew Ng Coursera学习总结合集,编程作业技巧合集

机器学习- 吴恩达Andrew Ng Coursera学习总结合集,编程作业技巧合集