weixin_40884083 2019-06-28 16:45 采纳率: 78.6%
浏览 1099
已结题

Octave 代价函数错误提示

1.题目来源:

吴恩达机器学习week2作业

2.代码内容(写在文档里)

function J = computeCost(X, y, theta)

%COMPUTECOST Compute cost for linear regression
% J = COMPUTECOST(X, y, theta) computes the cost of using theta as the
% parameter for linear regression to fit the data points in X and y

% Initialize some useful values
m = length(y); % number of training examples

% You need to return the following variables correctly
J = 0;

% ====================== YOUR CODE HERE ======================
% Instructions: Compute the cost of a particular choice of theta
% You should set J to the cost.

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

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

end

3.在Octave里面执行

运算是没有问题的
octave:6 J = computeCost(X, y, theta)
J = 0

但提交作业时候会报错,不知道为什么会跳出一个A矩阵。
A =

Diagonal Matrix

1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1

!! Submission failed: unexpected error: operator *: nonconformant arguments (op1 is 3x3, op2 is 2x1)
!! Please try again later.

  • 写回答

2条回答 默认 最新

  • threenewbee 2019-06-28 17:17
    关注

    矩阵乘法操作需要a的行和b的列,以及a的列和b的行的长度相等才能乘

    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?