title: How to change parameters of a scikit learn function dynamically i.e. find best parameter
body: <p>I am trying to do dimensionality reduction using PCA function of sklearn, specifically </p>
  
  <pre><code>from sklearn.decomposition import PCA
  
  def mypca(X,comp): 
  pca = PCA(n_components=comp)
  pca.fit(X)
  PCA(copy=True, n_components=comp, whiten=False)
  Xpca = pca.fit_transform(X)
  return Xpca
  
  for n_comp in range(10,1000,20):
      Xpca = mypca(X,n_comp) # X is a 2 dimensional array
      print Xpca
  </code></pre>
  
  <p>I am calling mypca function from a loop with different values for comp. I am doing this in order to find the best value of comp for the problem I am trying to solve. But mypca function always returns the same value i.e. Xpca irrespective of value of comp.<br>
  The value it returns is correct for first value of comp I send from the loop i.e. Xpca value which it sends each time is correct for comp = 10 in my case.</p>
  
  <p><strong>What should I do in order to find best value of comp?</strong></p>