title: key error not in index while cross validation
body: <p>I have applied svm on my dataset. my dataset is multi-label means each observation has more than one label.</p>
  
  <p>while <code>KFold cross-validation</code> it raises an error <code>not in index</code>.</p>
  
  <p>It shows the index from 601 to 6007 <code>not in index</code> (I have 1...6008 data samples).</p>
  
  <p>This is my code:</p>
  
  <pre class="lang-py prettyprint-override"><code>   df = pd.read_csv("finalupdatedothers.csv")
  categories = ['ADR','WD','EF','INF','SSI','DI','others']
  X= df[['sentences']]
  y = df[['ADR','WD','EF','INF','SSI','DI','others']]
  kf = KFold(n_splits=10)
  kf.get_n_splits(X)
  for train_index, test_index in kf.split(X,y):
      print("TRAIN:", train_index, "TEST:", test_index)
      X_train, X_test = X.iloc[train_index], X.iloc[test_index]
      y_train, y_test = y.iloc[train_index], y.iloc[test_index]
  
  SVC_pipeline = Pipeline([
                  ('tfidf', TfidfVectorizer(stop_words=stop_words)),
                  ('clf', OneVsRestClassifier(LinearSVC(), n_jobs=1)),
              ])
  
  for category in categories:
      print('... Processing {} '.format(category))
      # train the model using X_dtm &amp; y
      SVC_pipeline.fit(X_train['sentences'], y_train[category])
  
      prediction = SVC_pipeline.predict(X_test['sentences'])
      print('SVM Linear Test accuracy is {} '.format(accuracy_score(X_test[category], prediction)))
      print 'SVM Linear f1 measurement is {} '.format(f1_score(X_test[category], prediction, average='weighted'))
      print([{X_test[i]: categories[prediction[i]]} for i in range(len(list(prediction)))])
  </code></pre>
  
  <p>Actually, I do not know how to apply KFold cross-validation in which I can get the F1 score and accuracy of each label separately.
  having looked at <a href="http://scikit-learn.org/stable/modules/generated/sklearn.model_selection.KFold.html#sklearn.model_selection.KFold" rel="noreferrer">this</a> and <a href="https://stackoverflow.com/questions/16379313/how-to-use-the-a-k-fold-cross-validation-in-scikit-with-naive-bayes-classifier-a">this</a> did not help me how can I successfully to apply on my case.</p>
  
  <p><strong>for being reproducible, this is a small sample of the data frame</strong>
  the last seven features are my labels including ADR, WD,...</p>
  
  <pre><code>,sentences,ADR,WD,EF,INF,SSI,DI,others
  0,"extreme weight gain, short-term memory loss, hair loss.",1,0,0,0,0,0,0
  1,I am detoxing from Lexapro now.,0,0,0,0,0,0,1
  2,I slowly cut my dosage over several months and took vitamin supplements to help.,0,0,0,0,0,0,1
  3,I am now 10 days completely off and OMG is it rough.,0,0,0,0,0,0,1
  4,"I have flu-like symptoms, dizziness, major mood swings, lots of anxiety, tiredness.",0,1,0,0,0,0,0
  5,I have no idea when this will end.,0,0,0,0,0,0,1
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <p>when I did whatever Vivek Kumar said It raises the error </p>
  
  <pre><code>ValueError: Found input variables with inconsistent numbers of samples: [1, 5408]
  </code></pre>
  
  <p>in classifier part . do you have any idea how to resolve it?</p>
  
  <p>there are a couple of links for this error in stackoverflow which says I need to reshape training data. I also did that but no success <a href="https://stackoverflow.com/questions/35379200/valueerror-found-arrays-with-inconsistent-numbers-of-samples-6-1786">link</a>
  Thanks :)</p>