title: Principal Component Analysis not working
body: <p>I'm trying to do principal component analysis on datasets containing images, but whenever I want to apply pca.transform from the sklearn.decomposition module I keep getting this error: <strong>*AttributeError: 'PCA' object has no attribute 'mean_'*</strong>. I know what this error means, but I have no clue how to fix it. I reckon some of you guys know how to fix this.</p>
  
  <p>Thank you for your help</p>
  
  <p>My code:</p>
  
  <pre><code>from sklearn import svm
  import numpy as np
  import glob
  import os
  from PIL import Image
  from sklearn.decomposition import PCA
  
  image_dir1 = "C:\Users\private\Desktop\K FOLDER\private\train"
  image_dir2 = "C:\Users\private\Desktop\K FOLDER\private\test1"
  Standard_size = (300,200)
  pca = PCA(n_components = 10)
  file_open = lambda x,y: glob.glob(os.path.join(x,y))
  
  
  def matrix_image(image_path):
      "opens image and converts it to a m*n matrix" 
      image = Image.open(image_path)
      print("changing size from %s to %s" % (str(image.size), str(Standard_size)))
      image = image.resize(Standard_size)
      image = list(image.getdata())
      image = map(list,image)
      image = np.array(image)
      return image
  def flatten_image(image):  
      """
      takes in a n*m numpy array and flattens it to 
      an array of the size (1,m*n)
      """
      s = image.shape[0] * image.shape[1]
      image_wide = image.reshape(1,s)
      return image_wide[0]
  
  if __name__ == "__main__":
      train_images = file_open(image_dir1,"*.jpg")
      test_images = file_open(image_dir2,"*.jpg")
      train_set = []
      test_set = []
  
      "Loop over all images in files and modify them"
      train_set = [flatten_image(matrix_image(image)) for image in train_images]
      test_set = [flatten_image(matrix_image(image)) for image in test_images]
      train_set = np.array(train_set)
      test_set = np.array(test_set)
      train_set = pca.fit_transform(train_set) "line where error occurs"
      test_set = pca.fit_transform(test_set)
  </code></pre>
  
  <p>Full traceback:</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\Users\Private\workspace\final_submission\src\d.py", line 54, in &lt;module&gt;
      train_set = pca.transform(train_set)
    File "C:\Python27\lib\site-packages\sklearn\decomposition\pca.py", line 298, in transform
      if self.mean_ is not None:
  AttributeError: 'PCA' object has no attribute 'mean_'
  </code></pre>
  
  <p><strong>Edit1:</strong> 
  So I tried to fit the model before transforming it, and now I'm getting an even weirder error. I looked it up, and it involves f2py, a module that ports Fortran to Python which is part of the Numpy Library. </p>
  
  <pre><code>File "C:\Users\Private\workspace\final_submission\src\d.py", line 54, in &lt;module&gt;
      pca.fit(train_set)
    File "C:\Python27\lib\site-packages\sklearn\decomposition\pca.py", line 200, in fit
      self._fit(X)
    File "C:\Python27\lib\site-packages\sklearn\decomposition\pca.py", line 249, in _fit
      U, S, V = linalg.svd(X, full_matrices=False)
    File "C:\Python27\lib\site-packages\scipy\linalg\decomp_svd.py", line 100, in svd
      full_matrices=full_matrices, overwrite_a = overwrite_a)
  ValueError: failed to create intent(cache|hide)|optional array-- must have defined dimensions but got (0,)
  </code></pre>
  
  <p><strong>Edit2:</strong>      </p>
  
  <p>So I have checked if my train_set and data_set contained any data and they don't. 
  I've checked my image_dirs, and they contain the right locations(just for clarity, I got them by going to the actual files, looking at the properties of one the images and copied the location). The fault should lie somewhere else. </p>