Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在MATLAB中为神经网络提供测试样本?_Matlab_Image Processing_Neural Network - Fatal编程技术网

如何在MATLAB中为神经网络提供测试样本?

如何在MATLAB中为神经网络提供测试样本?,matlab,image-processing,neural-network,Matlab,Image Processing,Neural Network,在MATLAB经典螃蟹分类问题中,神经网络仅从提供的样本中选择测试样本。假设,如果我向神经网络提供30个样本,它会随机抽取其中的5个样本作为测试样本 是否可以从用户端指定测试样本 fid = fopen('/featureValues.csv'); C = textscan(fid,'%f%f%f%f%s','delimiter',','); % Import data fclose(fid); %% % The first 4 columns of data represent the i

在MATLAB经典螃蟹分类问题中,神经网络仅从提供的样本中选择测试样本。假设,如果我向神经网络提供30个样本,它会随机抽取其中的5个样本作为测试样本

是否可以从用户端指定测试样本

fid = fopen('/featureValues.csv');
C = textscan(fid,'%f%f%f%f%s','delimiter',',');  % Import data
fclose(fid);

%%
% The first 4 columns of data represent the image's features
% The 5th column represents the category of the image.

features = [C{1} C{2} C{3} C{4}]; % inputs to neural network

tiger = strncmpi(C{5}, 'tiger', 1);
lion = strncmpi(C{5}, 'lion', 1);
dino = strncmpi(C{5}, 'Dino', 1);

%Encoding the image categories
imCat = double([tiger lion dino]);                 % targets for neural network

% The next step is to preprocess the data into a form that can be used with
% a neural network.
%
% The neural network object in the toolbox expects the samples along
% columns and its features along rows. Our dataset has its samples along
% rows and its features along columns. Hence the matrices have to be
% transposed.

features = features';
imCat = imCat';

%% Building the Neural Network Classifier
% The next step is to create a neural network that will learn to identify
% the class of the images.
%
% Since the neural network starts with random initial weights, the results
% of this demo will differ slightly every time it is run. The random seed
% is set to avoid this randomness. However this is not necessary for your
% own applications.

rand('seed', 491218382)

%%
% A 1-hidden layer feed forward network is created with 20 neurons in the
% hidden layer.
%

net = newff(features,imCat,20); % Create a new feed forward network


% Now the network is ready to be trained.

[net,tr] = train(net,features,imCat);

%% Testing the Classifier
testInputs = features(:,tr.testInd);
testTargets = imCat(:,tr.testInd);

out = net(testInputs);        % Get response from trained network

[y_out,I_out] = max(out);
[y_t,I_t] = max(testTargets);

N = size(testInputs,2);               % Number of testing samples
fprintf('Total testing samples: %d\n', N);

他们解释了如何使用不同的数据划分模式。从这个问题来看,您似乎是在专门寻找,以便可以通过索引指定培训、验证和测试数据

你能给我们看看你正在使用的代码吗?@rayryeng,我已经添加了代码。请建议我应该如何进行。