!! Submission failed: unexpected error: Error using computeCost Too many output arguments.
이전 댓글 표시
When I put this expression in MATlab I get:
!! Submission failed: unexpected error: Error using computeCost
Too many output arguments.
!! Please try again later.
function J = computeCost(X, y, theta)
data = load('ex1data1.txt');
m = 97;
X = [ones(m, 1), data(:,1)];
theta = zeros(2, 1);
h = X * theta;
y = data(:, 2);
error = h - y;
error_sqr = error.^2;
q = sum(error_sqr);
J = (1/ (2*m) * q)
댓글 수: 3
Walter Roberson
2020년 4월 15일
Why are you overwriting the input X and y and theta?
What is the point of setting theta to 0 and then multiplying by theta ?
How can you be certain that data will always have exactly 97 rows?
Martin Felipe Wohlgemuth Pinzon
2020년 4월 15일
Walter Roberson
2020년 4월 17일
function J = computeCost(X, y, theta)
That line tells you that X, y, and theta are normally expected to be passed in as inputs.
data = load('ex1data1.txt');
m = 97;
Neither of those lines read or write X, y, or theta, so the input X, y, theta do not matter to those two lines.
X = [ones(m, 1), data(:,1)];
theta = zeros(2, 1);
h = X * theta;
y = data(:, 2);
The first of those lines ignores any X that was passed in and overwrites X with values. The second discards theta that was passed in and overwrites theta with zeros. The fourth line discards y that was passed in and overwrites y with values.
Therefore no matter what was passed in for X, y, theta, the code will ignore them and do its own thing.
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Time Series Objects에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!