【发布时间】:2017-09-16 14:42:41
【问题描述】:
我有 200 个训练示例。我已经在这个数据集上运行了具有 6 个特征的线性回归并且它运行良好,所以我也想在它上面运行 nueral 网络。
问题:每次我运行程序,预测(pred)都不同,非常不同!
input_layer_size = 6;
hidden_layer_size = 3;
num_labels = 1;
% Load Training Data
load('capitaldata.mat');
% example size
m = size(X, 1);
% initialize theta
initial_Theta1 = randInitializeWeights(input_layer_size, hidden_layer_size);
initial_Theta2 = randInitializeWeights(hidden_layer_size, num_labels);
% Unroll parameters
initial_nn_params = [initial_Theta1(:) ; initial_Theta2(:)];
% find optimal theta
options = optimset('MaxIter', 50);
% set regularization parameter
lambda = 1;
% Create "short hand" for the cost function to be minimized
costFunction = @(p) nnCostFunctionLinear(p, input_layer_size, hidden_layer_size, num_labels, X, y, lambda);
% Now, costFunction is a function that takes in only one argument (the neural network parameters)
[nn_params, cost] = fmincg(costFunction, initial_nn_params, options);
% Obtain Theta1 and Theta2 back from nn_params
Theta1 = reshape(nn_params(1:hidden_layer_size * (input_layer_size + 1)), hidden_layer_size, (input_layer_size + 1));
Theta2 = reshape(nn_params((1 + (hidden_layer_size * (input_layer_size + 1))):end), num_labels, (hidden_layer_size + 1));
% test case
test = [18 279 86 59 23 16];
pred = predict(Theta1, Theta2, test);
display(pred);
上述程序调用的函数:
1) randInitializeWeights.m
function W = randInitializeWeights(L_in, L_out)
W = zeros(L_out, 1 + L_in);
epsilon_init = 0.12;
W = rand(L_out , 1 + L_in) * 2 * epsilon_init - epsilon_init;
end;
2) nnCostFunctionLinear.m 应该是正确的,因为测试结果是正确的。如果你也想看,请告诉我。
我怀疑问题出在数据集大小、特征数量或初始化权重上。
提前感谢您的帮助!
【问题讨论】:
-
我不熟悉八度,但这似乎是一个随机数的问题。结果肯定会有所不同,因为初始权重在每一轮都是随机的。但是你说它们有很大的不同。你能再描述一下吗,可能在这里添加结果
-
是肯定的:预测是 2.1687e+004、-2.4438e+004、-7226.6 等。而结果应该在 31 左右。我也关注随机化,但我从 Coursera 的机器学习是反向传播需要随机的 theta 而不是全零的 theta,否则它会卡在一个鞍点...... :( 真的很困惑!
-
我很困惑。您是说预测与实际数据大不相同,还是在不同的算法运行中预测彼此大不相同?
-
两者,不幸的是......有时是正面的,有时是负面的,但在训练示例中,它们从来都不是负面的(它们在10~200之间)。
标签: machine-learning neural-network octave linear-regression backpropagation