吴恩达机器学习machine-learning-ex1题解及经验

  1. 第一题
    1 Simple Octave/MATLAB function
    The first part of ex1.m gives you practice with Octave/MATLAB syntax and the homework submission process. In the file warmUpExercise.m, you will find the outline of an Octave/MATLAB function. Modify it to return a 5 x5 identity matrix by filling in the following code:
    意思是说要写一个warmUpExercise函数 运行该函数会输出一个5*5的单位矩阵
在warmUpExercise函数中进行编写即可
A = eye(5)
  1. 第二题
    2.1 Plotting the Data

进入plotData中输入以下代码即可

plot(x, y, 'rx', 'MarkerSize', 10); % Plot the data
ylabel('Profit in $10,000s'); % Set the y−axis label
xlabel('Population of City in 10,000s'); % Set the x−axis label
  1. 第三题
    2.2.3 Computing the cost J(θ) 在computeCost.m,中计算代价函数。
    由定义可以知道
    在这里插入图片描述
    在这里插入图片描述
    代码为
predict = X * theta;
sqrError = (predict-y).^2;
J = 1/(2*m)*sum(sqrError);
  1. 第四题

Gradient descent
在这里插入图片描述
在这里插入图片描述
代码

 group = X'*(X*theta-y);
    theta = theta-(alpha/m)*group; 
    注意:在进行矩阵的乘法时 假设A(m*n)*B(k*q) m一定要等于q 否则会报错
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值