0

I have a CSV file with two columns, 'sentence' is string of sentences, emoID is 1-7 integer such as following:

sentence           emoID
During the period of falling in love.       1
When I was involved in a traffic accident.  2
 .....                                      ...

I need to classify each sentence to its corresponding emoID. I saw a example that classify two classes likes follow:

# Generate labels
positive_labels = [[0, 1] for _ in positive_examples]
negative_labels = [[1, 0] for _ in negative_examples]

Now I have 7 classes rather than two, how could I generate 7 labels for each class? I am beginner of python, many thanks for your help!

Ivan Kolesnikov
  • 1,787
  • 1
  • 29
  • 45
user2332706
  • 39
  • 1
  • 2
  • 6

1 Answers1

0

You could use an array with 7 entries, for class n having entry 1 at position n in the array with the rest 0. E.g. class 3: [0,0,1,0,0,0,0] And:

c3_labels = [[0,0,1,0,0,0,0] for _ in c3_examples]
molig
  • 314
  • 2
  • 6
  • Yes, this is what I thought.Is the 'for _ in c3_examples' means append [0,0,1,0,0,0,0] into c3_examples? – user2332706 Nov 28 '16 at 13:26
  • Sorry, I misunderstood your question. `c3_labels = [[0,0,1,0,0,0,0] for _ in c3_examples]` will just create an array which contains the label array `len(c3_labels)` times. So, if you have three samples of class 3 the varible c3_labels will contain `[[0, 0, 1, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0]]`. You can then use this array and append it as new 'column' to your sample data. – molig Nov 28 '16 at 17:25