neural network toolbox classification?

2 vues (au cours des 30 derniers jours)
Beyond
Beyond le 28 Avr 2012
Hi,
I'm starting to learn nntool and I'd like to know if it's possible to do the following:
I have text data, like this:
  1. apple, red, small, 1
  2. apple, red, small, 1
  3. apple, red, big, -4
  4. apple, red, big, 1
  5. apple, yellow, small, 1
  6. apple, yellow, small, 1
  7. apple, yellow, big, -4
  8. apple, yellow, big, 1
  9. apple, green, small, 1
  10. apple, green, small, 1
  11. apple, green, big, -4
  12. apple, green, big, 1
and so on, with banana, cherry, etc, just the numbers in the last column are different, but all fitting a simple pattern.
I'd like to use this as training data, and then input to the network a question like:
apple, green, big, ?
and get a result for the "?".
Can that be done in matlab? If yes, could someone describe it in short? At the moment I can't even enter the data properly, importing detects just the last column, the one with numbers.
  1 commentaire
Greg Heath
Greg Heath le 28 Avr 2012
Which answer do you want ...
11. apple, green, big, -4
or
12. apple, green, big, 1
Why, and what do the numbers mean?
Greg

Connectez-vous pour commenter.

Réponses (5)

Walter Roberson
Walter Roberson le 28 Avr 2012
importdata() and csvread() are for numeric data only. Use textscan()
fid = fopen('YourFileName', 'rt');
datacell = textscan('%s%s%s%d', 'Delimiter', ',');
fclose(fid);
Now datacell{1} will be column 1, datacell{2} column 2, datacell{3} column 3, and datacell{4} would be the numbers.
I am assuming here that the "4." and so on are not part of the file.

Beyond
Beyond le 28 Avr 2012
Thanks, that might take care of the import, though the "4" - the column with numbers is part of the file. Not sure how to define this, I think for example the "apple, red, small" would go in, and the weights should be adjusted so that output is "1". Should the strings be transformend somehow into numbers? Then I'd like to insert something without an output, and get it based on the input. It's how neural networks can work, in my understanding. How can I do it in Matlab?
  2 commentaires
Greg Heath
Greg Heath le 29 Avr 2012
If you answer my questions I may be able to help (even though I don't appreciate being ignored :( ).
Greg
Walter Roberson
Walter Roberson le 29 Avr 2012
To check: you show us example input in which there are two numbers per line. Do both numbers exist in the file, or is the only number in each line the one at the end of the line?
If both numbers exist in the file, it gets harder to read the data because the leading number would form a column that is not delimited with comma like the other columns are.
datacell = textscan('*f%[^,],%[^,],%[^,],%d');
I do not know much about NN, but I would think it would be easier if you were to convert the strings into numbers.

Connectez-vous pour commenter.


Greg Heath
Greg Heath le 30 Avr 2012
Inputs to a MATLAB TBX NN are column vectors. The first three inputs are categorical and can be represented by binary numbers. For example, if the food class contains the four categories apple, banana, cherry and pepper, the corresponding categorical indices [ 1 2 3 4]are converted to the corresponding part of the 4-dimensional unit matrix obtained via the command ind2vec(index). Similarly for the color indices [1 2 3] representing red, green and yellow and size indices [1 2 3] representing small, average and big.
Consequently, a big red apple { 1 1 3 } is represented by the input column vector
[ [ 1 0 0 0]' ; [ 1 0 0 ]' ; [ 0 0 1 ]' ]
Untill I know what that last number in the OP's post is supposed to represent, I will omit it's representation.
For the ouput: There are 4*3*3 = 24 categories. Therefore the output can be represented by a column of the 24-dimensional unit matrix.
Hope this helps.
Greg

Beyond
Beyond le 30 Avr 2012
Sorry greg, that was a typo - each set of variables, like "apple, red, small" has a unique number assigned to it - it's a result of some trial experiment. The numbers for different sets might be the same though, like for "apple, red, small" and "apple, green, big".
Thanks for the reply, why do I have to use the conversion to binary numbers, wouldn't using numbers instead of categories work as well (like apple = 1, banana = 2, cherry = 3 and so on)?
Can all that you wrote about be done in the nntool? Or do I have to use the "command line"?

Greg Heath
Greg Heath le 30 Avr 2012
The comp.ai.neural-nets FAQ recommends bipolar binary coding { -1, 1} for input categorical variables and unipolar binary coding { 0, 1 } for output categorical variables. The corresponding recommended activation units are tanh(TANSIG) for hidden layers and SOFTMAX for the output layer.
For detailed discussions consult:
How should categories be encoded?
Why not code binary inputs as 0 and 1?
How to measure importance of inputs?
I am not that familiar with the nntool. However, it would be a good idea for you to try it first.
Hope this helps.
Greg
  1 commentaire
Greg Heath
Greg Heath le 30 Avr 2012
You still haven't explained what the number at the end of each row
represents!
Greg

Connectez-vous pour commenter.

Catégories

En savoir plus sur Deep Learning Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by