【发布时间】:2020-03-19 01:41:40
【问题描述】:
我目前正在使用 MNIST 数据集在 MATLAB 中做一个项目。我有一个 n = 50000 的训练数据集,由 784 x 50000 的矩阵表示(50000 个大小为 784 的列向量)。
我正在尝试将我的训练和测试数据(分别为 70-30)分开,但我使用的方法有点罗嗦,而且我喜欢蛮力。既然这是 MATLAB,我相信一定有更好的方法。下面列出了我一直在使用的代码。我是 MATLAB 的新手,所以请帮忙!谢谢:)
% MNIST - data loads into trn and trnAns, representing
% the input vectors and the desired output vectors, respectively
load('Data/mnistTrn.mat');
mnist_train = zeros(784, 35000);
mnist_train_ans = zeros(10, 35000);
mnist_test = zeros(784, 15000);
mnist_test_ans = zeros(10, 15000);
indexes = zeros(1,50000);
for i = 1:50000
indexes(i) = i;
end
indexes(randperm(length(indexes)));
for i = 1:50000
if i <= 35000
mnist_train (:,i) = trn(:,indexes(i));
mnist_train_ans(:,i) = trnAns(:,indexes(i));
else
mnist_test(:,i-35000) = trn(:,indexes(i));
mnist_test_ans(:,i-35000) = trnAns(:,indexes(i));
end
end
【问题讨论】:
标签: matlab matrix vector neural-network artificial-intelligence