我已经在这个问题上挣扎了很长时间了。我似乎弄不明白为什么我会有几千个百分比的误差。我正在尝试找出X1和X2之间的感知器,这是具有不同均值和相同协方差的高斯分布数据集。我的代码:
N=200;
X = [X1; X2];
X = [X ones(N,1)]; %bias
y = [-1*ones(N/2,1); ones(N/2,1)]; %classification
%Split data into training and test
ii = randperm(N);
Xtr = X(ii(1:N/2),:);
ytr = X(ii(1:N/2),:);
Xts = X(ii(N/2+1:N),:);
yts = y(ii(N/2+1:N),:);
w = randn(3,1);
eta = 0.001;
%learn from training set
for iter=1:500
j = ceil(rand*N/2);
if( ytr(j)*Xtr(j,:)*w < 0)
w = w + eta*Xtr(j,:)';
end
end
%apply what you have learnt to test set
yhts = Xts * w;
disp([yts yhts])
PercentageError = 100*sum(find(yts .*yhts < 0))/Nts;任何帮助都将不胜感激。谢谢
发布于 2014-10-26 05:26:00
你的误差计算中有一个错误。
在这一行上:
PercentageError = 100*sum(find(yts .*yhts < 0))/Nts;find正在返回匹配项的索引。为了测量准确度,你不需要这些,你只需要计数:
PercentageError = 100*sum( yts .*yhts < 0 )/Nts;如果我生成X1 = randn(100,2); X2 = randn(100,2);并假设为Nts=100,您的代码将获得2808%的错误,而更正后的版本将出现50%的错误(不会比猜测更好,因为我的测试数据无法分离)。
更新-感知器模型也有一个更微妙的错误,请参阅:https://datascience.stackexchange.com/questions/2353/matlab-perceptron
https://stackoverflow.com/questions/26567120
复制相似问题