Machine learning 神经网络预测 我正在安得烈教授的NGL课程上工作。 问题就在这里。 我正在尝试实现以下模型:

Machine learning 神经网络预测 我正在安得烈教授的NGL课程上工作。 问题就在这里。 我正在尝试实现以下模型: ,machine-learning,neural-network,octave,Machine Learning,Neural Network,Octave,,这是我的代码: function p = predict(Theta1, Theta2, X) %PREDICT Predict the label of an input given a trained neural network % p = PREDICT(Theta1, Theta2, X) outputs the predicted label of X given the % trained weights of a neural network (Theta1, Thet

,这是我的代码:

function p = predict(Theta1, Theta2, X)
%PREDICT Predict the label of an input given a trained neural network
%   p = PREDICT(Theta1, Theta2, X) outputs the predicted label of X given the
%   trained weights of a neural network (Theta1, Theta2)

% Useful values
m = size(X, 1);
num_labels = size(Theta2, 1);

% You need to return the following variables correctly 
p = zeros(size(X, 1), 1);

% ====================== YOUR CODE HERE ======================
% Instructions: Complete the following code to make predictions using
%               your learned neural network. You should set p to a 
%               vector containing labels between 1 to num_labels.
%
% Hint: The max function might come in useful. In particular, the max
%       function can also return the index of the max element, for more
%       information see 'help max'. If your examples are in rows, then, you
%       can use max(A, [], 2) to obtain the max for each row.
%

X = [ones(m,1) X];%X:5000*401

z2 = Theta1*X';%z2: 25*5000
z2_n = size(z2,2);%

a2 = [sigmoid(z2); ones(1,z2_n)];%theta1_x: 26*5000

z3 = Theta2*a2;%z3: 10*5000
a3 = sigmoid(z3);

[a, p] = max(a3, [], 1);

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


end
但是我得到了很多错误的预测,实现的哪一部分是错误的?
感谢您的建议。

问题始于计算
z2

z2 = X * Theta1';
a2 = [ones(size(z2, 1), 1) sigmoid(z2)];
z3 = a2 * Theta2';
a3 = sigmoid(z3);
[pmax, p] = max(a3, [], 2)

这是八度音阶吗?是的。对不起,忘了提了。你的z2不是和我的一样,只是换位了吗?哦,我想我找到问题了。我应该在sigmoid(z2)之前加上1(1,z2),对吗?好吧,你取了X的转置。但是我相信你应该取θ的转置。请用mine改变相应的变量。我想这会解决你的问题