title: Python IndexError: index 1 is out of bounds for LDA
body: <p>I have a dataset that looks like this:</p>
  
  <pre><code>    Out  Revolver   Ratio     Num ...
  0   1    0.766127   0.802982  0   ...
  1   0    0.957151   0.121876  1 
  2   0    0.658180   0.085113  0 
  3   0    0.233810   0.036050  3 
  4   1    0.907239   0.024926  5 
  ...
  </code></pre>
  
  <p><code>Out</code> can only take only values 0 and 1.
  I then tried to generate PCA and LCA plots using the code below that is similar to here: <a href="http://scikit-learn.org/stable/auto_examples/decomposition/plot_pca_vs_lda.html" rel="nofollow">http://scikit-learn.org/stable/auto_examples/decomposition/plot_pca_vs_lda.html</a></p>
  
  <pre><code>features = Train.columns[1:]
  Xf = newTrain[features]
  yf = newTrain.Out
  pca = PCA(n_components=2)
  X_r = pca.fit(Xf).transform(Xf)
  lda = LinearDiscriminantAnalysis(n_components=2)
  X_r2 = lda.fit(Xf, yf).transform(Xf)
  
  plt.figure()
  for c, i, name in zip("rgb", [0, 1], names):
      plt.scatter(X_r[yf == i, 0], X_r[yf == i, 1], c=c, label=name)
  plt.legend()
  plt.title('PCA plt')
  
  plt.figure()
  for c, i, name in zip("rgb", [0, 1], names):
      plt.scatter(X_r2[yf == i, 0], X_r2[yf == i, 1], c=c, label=name)
  plt.legend()
  plt.title('LDA plt')
  </code></pre>
  
  <p>I can get the PCA plot to work. However, it doesn't make sense as it only shows 2 dots. One at around (-4000, 30) and the other at (2400, 23.7). I don't see a bunch of data points like in the plot in that link</p>
  
  <p>The LDA plot doesn't work and gives the error </p>
  
  <blockquote>
    <p>IndexError: index 1 is out of bounds for axis 1 with size 1</p>
  </blockquote>
  
  <p>I also tried the code below to generate an LDA plot but got the same error</p>
  
  <pre><code>for c, i, name in zip("rgb", [0, 1], names):
      plt.scatter(x=X_LDA_sklearn[:, 0][yf==i], y=X_LDA_sklearn[:, 1][yf==i], c=c, label=name)
  plt.legend()
  </code></pre>
  
  <p>Anyone know what's wrong with this?</p>
  
  <p>EDIT: Here are my imports</p>
  
  <pre><code>import pandas as pd
  from pandas import Series,DataFrame
  import numpy as np
  import matplotlib.pyplot as plt
  import seaborn as sns
  import csv
  
  from sklearn.linear_model import LogisticRegression
  from sklearn.cross_validation import train_test_split
  from sklearn import metrics
  from sklearn.decomposition import PCA
  from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
  from sklearn.lda import LDA
  </code></pre>
  
  <p>As for where the errors are occuring:</p>
  
  <p>I get </p>
  
  <pre><code>FutureWarning: in the future, boolean array-likes will be handled as a boolean array index
  plt.scatter(X_r[yf == i,0], X_r[yf == i, 1], c=c, label=name)
  </code></pre>
  
  <p>at the line inside the for loop for the PCA plot</p>
  
  <p>As for the LDA at the line</p>
  
  <pre><code>plt.scatter(X_r2[yf == i, 0], X_r2[yf == i, 1], c=c, label=name)
  </code></pre>
  
  <p>I get </p>
  
  <pre><code>FutureWarning: in the future, boolean array-likes will be handled as a boolean array index
  </code></pre>
  
  <p>and</p>
  
  <pre><code>IndexError: index 1 is out of bounds for axis 1 with size 1
  </code></pre>