0
내가로부터 코드를 사용하여 그라데이션 하강을 구현하려고 해요
X = [1; 1; 1;]
y = [1; 0; 1;]
m = length(y);
X = [ones(m, 1), data(:,1)];
theta = zeros(2, 1);
iterations = 2000;
alpha = 0.001;
for iter = 1:iterations
theta = theta -((1/m) * ((X * theta) - y)' * X)' * alpha;
end
theta
하는 출력 다음주는 : 다음에
Gradient Descent implementation in octave
내가 수정 한 코드
X =
1
1
1
y =
1
0
1
theta =
0.32725
0.32725
theta는 1x2 매트릭스이지만 1x3이 아니어야합니다 출력 (y)는 3x1?
그래서 예를 들어 훈련 예제로 곱 해져야하지만 x가 1x3이고 theta가 1x2이므로 x를 theta로 곱할 수 없습니까?
업데이트 : 여기
%X = [1 1; 1 1; 1 1;]
%y = [1 1; 0 1; 1 1;]
X = [1 1 1; 1 1 1; 0 0 0;]
y = [1 1 1; 0 0 0; 1 1 1;]
m = length(y);
X = [ones(m, 1), X];
theta = zeros(4, 1);
theta
iterations = 2000;
alpha = 0.001;
for iter = 1:iterations
theta = theta -((1/m) * ((X * theta) - y)' * X)' * alpha;
end
%to make prediction
m = size(X, 1); % Number of training examples
p = zeros(m, 1);
htheta = sigmoid(X * theta);
p = htheta >= 0.5;
세타 세타 × 10 인 경우
y
로서 * 세타? theta가 2x2이면 가설은 h (x) = x1 * theta1 + theta0이되어야합니다. – thepentheta는 항상'[K + 1] xD'가 될 것입니다. 여기서 X는'NxK'이고 y는'NxD'입니다. – lejlot