!! 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!