Coursera——Machine Learning (linear Regression) week2 编程作业答案

这篇博客涵盖了Coursera上Andrew Ng的机器学习课程第二周的编程作业。内容包括:实现5x5单位矩阵、绘制散点图、计算单变量和多变量的代价函数、使用梯度下降法求解θ、特征归一化以及利用正规方程直接求解θ的最优值。作业涉及Octave命令行操作,对理解线性回归概念和算法实践具有指导意义。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、warmUpExercise.m:输出一个5*5的单位矩阵(identity matrix)

function A = warmUpExercise()
%WARMUPEXERCISE Example function in octave
%   A = WARMUPEXERCISE() is an example function that returns the 5x5 identity matrix

A = [];
% ============= YOUR CODE HERE ==============
% Instructions: Return the 5x5 identity matrix 
%               In octave, we return values by defining which variables
%               represent the return values (at the top of the file)
%               and then set them accordingly. 


A=eye(5);




% ===========================================


end

在Octave中输入命令为:
这里写图片描述
2、plotData.m:绘制一个散点图

function plotData(x, y)
%PLOTDATA Plots the data points x and y into a new figure 
%   PLOTDATA(x,y) plots the data points and gives the figure axes labels of
%   population and profit.

figure; %打开一个新的图像窗口

% ====================== YOUR CODE HERE ======================
% Instructions: Plot the training data into a figure using the 
%               "figure" and "plot" commands. Set the axes labels using
%               the "xlabel" and "ylabel" commands. Assume 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值