title: Run a Principal Component Analysis (PCA) on the dataset to reduce the number of features (components) from 64 to 2
body: <p>I'm trying to reduce my components to 2 instead of 64 but I keep getting this error:
  "Length mismatch: Expected axis has 64 elements, new values have 4 elements"
  Why is the PCA I'm running on the data set not changing the number to 2?</p>
  
  <p>This is what I have:</p>
  
  <pre><code>import matplotlib.pyplot as plt
  from sklearn import datasets
  from sklearn.cluster import KMeans
  import sklearn.metrics as sm
  
  import pandas as pd
  import numpy as np
  
  
  import scipy
  from sklearn import decomposition
  
  digits = datasets.load_digits()      #load the digits dataset instead of the iris dataset
  
  
  x = pd.DataFrame(digits.data)     #was(iris.data)
  x.columns = ['Sepal_L', 'Sepal_W', 'Sepal_L', 'Sepal_W']
  
  plt.cla()
  pca = decomposition.PCA(n_components=2)
  pca.fit(x)
  x = pca.transform(x)
  
  
  y = pd.DataFrame(digits.target)
  y.columns = ['Targets']
  
  # this line actually builds the machine learning model and runs the algorithm
  # on the dataset
  model = KMeans(n_clusters = 10)    #Run k-means on this datatset to cluster the data into 10 classes
  model.fit(x)
  
  #print(model.labels_)
  
  
  colormap = np.array(['red', 'blue', 'yellow', 'black'])
  
  # Plot the Models Classifications
  plt.subplot(1, 2, 2)
  plt.scatter(x.Petal_L, x.Petal_W, c=colormap[model.labels_], s=40)
  plt.title('K Means Classification')
  
  plt.show()
  </code></pre>