classifying data files in a folder with neural network

Hi there,
I was hoping somebody could advise me on how to achieve something with neural networks.
I used the neural network pattern recognition tool GUI to create a network for data classification.
I saved the network as net.mat
What I would like to do is, loop through files in the current work folder, which contain normalized inputs and run these through the network. Then save each ouput with same name as the input - so I can identify them at a later stage.
I'm not good coding but I suppose an attempt would be something like this:
files = dir('*.txt');
for k = 1:numel(files)
output = sim(net, files(k).name)
%save the output with the same name as input to E:\NNoutput
end
I would really appreciate any advice
Thank you
John

2 comentarios

Can you give me one example of the txt file?
I need to know how do you format it.
John
John el 10 de En. de 2012
Hi,
Thanks for replying.
The text files contain column vectors as inputs each one with 30 elements.
I've attached a link to sample in a dropbox. This particular one contains two column vectors, but others would contain more (20-30).
http://dl.dropbox.com/u/54057365/NNinput.txt
So I was hoping to pass each file containing the column vectors into the neural network to classify the data, as being of type 1,2,3. Then save the output with the same name as the input file.
Does it have to saved as a .mat file of can it be saved as a .txt file?
Many thanks for your help
Please come back to me if I have not explained that well
John

Iniciar sesión para comentar.

 Respuesta aceptada

Hi,
This is the code that I created.
If there is an error, please tell me.
files = dir(fullfile(pwd,'*.txt'));
for k = 1 : numel(files)
%%%%reading the txt file
fid01 = fopen(fullfile(pwd,files(k).name));
idx = 0; tmparray = [];
tline = fgetl(fid01);
while ischar(tline)
idx = idx + 1;
tmparray(idx,:) = str2num(tline);
tline = fgetl(fid01);
end
fclose(fid01);
%%%%simulate net
output = sim(net, tmparray);
%%%%save the output
filename = strcat(regexprep(files(k).name,'.txt',''),'-output.txt');
fid02 = fopen(filename,'w');
fprintf(fid02,'%.2f\n',output');
fclose(fid02);
end

6 comentarios

John
John el 11 de En. de 2012
Thank you - I'll try it now
John
John
John el 11 de En. de 2012
Thank you - that seems to be working just fine.
John
John
John el 23 de En. de 2012
Hi Chandra,
I've been using your code successfully, but I was wondering/hoping if it would be possible to make a change to the format of the output file, it would be a great help. I would do it myself but I have the knowledge.
At the moment the output is a 1x1 array. For example
output = [
0
0
0
0
1
1
1
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
]
Would it be possible to convert it into a sparse matrix like this
output = full(output)
0 0 0 0
1 1 1 0
0 0 0 1
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
and then convert it to vectors , for example
Output = vec2ind(output)
2 2 2 3
All this might not be necessary, this is just the way I thought it might work.
Thank you for your help
John
Freedom
Freedom el 18 de Ag. de 2013
Hi,
Is the code u post is the complete one? But there's no output came out. Can you email me the full code? I need it emergency.
Thank you.
Freedom
Freedom el 19 de Ag. de 2013
What type of neural network are u using?
If you only have 3 classes, the size of your output should only have 3 rows. The corresponding training target matrix should have only had columns of the unit matrix eye(3).
trueclass = vec2ind(target)
assignedclass = vec2ind(output)
err = assignedclass ~= trueclass
Nerr = sum(err)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Deep Learning Toolbox en Centro de ayuda y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by