title: Sentimental analysis with Naive Bayes classification using Mahout
body: <p>I'm trying to train a Naive Bayes classifier with Mahout.</p>
  
  <p>The first thing that isn't quite clear to me is how should my training data look like. My data  set consists of an opinion and if it's positive or negative(1 for positive, -1 for negative.) From what I understood from the chapter about classification in the Mahout in Action book, I've set up my training data like so: </p>
  
  <pre><code> 1   'Content of positive opinion'
  -1   'Content of negative opinion'
  </code></pre>
  
  <p>I've turned this data into a sequence file using seqdirectory and I'm training the classifier with this command:</p>
  
  <pre><code>$MAHOUT_HOME/bin/mahout trainnb -i seq_data/chunk-0 -o bmodel -ow
  </code></pre>
  
  <p>which outputs this error:</p>
  
  <pre><code>Exception in thread "main" java.io.FileNotFoundException: File temp/labelIndex does not exist.
  </code></pre>
  
  <p>Looking through the options accepted by trainnb, I saw the --labelIndex option. I'm not exactly sure what this does, I could use some clarification for this.</p>
  
  <p>Then I ran the command like so(where lindex is a file I created):</p>
  
  <pre><code>$MAHOUT_HOME/bin/mahout trainnb -i seq_data/chunk-0 -o bmodel -ow -li lindex
  </code></pre>
  
  <p>which outputs this error: </p>
  
  <pre><code>java.lang.ClassCastException: org.apache.hadoop.io.Text cannot be cast to org.apache.mahout.math.VectorWritable
      at org.apache.mahout.classifier.naivebayes.training.IndexInstancesMapper.map(IndexInstancesMapper.java:29)
      at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:144)
      at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:764)
      at org.apache.hadoop.mapred.MapTask.run(MapTask.java:370)
      at org.apache.hadoop.mapred.LocalJobRunner$Job.run(LocalJobRunner.java:212)
  </code></pre>
  
  <p>I'd like to know what I'm doing wrong here, if my approach is incorrect. How should I structure the training data and run the command?</p>