<p dir="auto">While testing the class_weight parameter in several estimators to investigate <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="8682377" data-permission-text="Title is private" data-url="https://github.com/scikit-learn/scikit-learn/issues/1411" data-hovercard-type="issue" data-hovercard-url="/scikit-learn/scikit-learn/issues/1411/hovercard" href="https://github.com/scikit-learn/scikit-learn/issues/1411">#1411</a>, I noticed that the parameter doesn't work as I would expect in RidgeClassifier either.<br>
Maybe this is some misunderstanding on my part or some regularization issue, but if I have noisy labels, I would have expected to be be able to move the decision boundary.</p>
<p dir="auto">This is not the case as illustrated in <a href="http://nbviewer.ipython.org/4369742/" rel="nofollow">this notebook</a></p>
<p dir="auto">Any input would be appreciated.</p>
<p dir="auto">When using the <code class="notranslate">sklearn.decomposition.PCA</code> class with <code class="notranslate">n_components='mle'</code> when svd_solver='auto' the following line will attempt to evaluate <code class="notranslate">n_components</code> as a numeric type. An additional safety check is necessary.</p>
<h1 dir="auto">Error</h1>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
&lt;ipython-input-22-26ffe206b6e0&gt; in &lt;module&gt;()
----&gt; 1 model = PCA(n_components='mle').fit(X_tr)

~/.conda/envs/Science3/lib/python3.6/site-packages/sklearn/decomposition/pca.py in fit(self, X, y)
    327             Returns the instance itself.
    328         &quot;&quot;&quot;
--&gt; 329         self._fit(X)
    330         return self
    331 

~/.conda/envs/Science3/lib/python3.6/site-packages/sklearn/decomposition/pca.py in _fit(self, X)
    382             if max(X.shape) &lt;= 500:
    383                 svd_solver = 'full'
--&gt; 384             elif n_components &gt;= 1 and n_components &lt; .8 * min(X.shape):
    385                 svd_solver = 'randomized'
    386             # This is also the case of n_components in (0,1)

TypeError: '&gt;=' not supported between instances of 'str' and 'int'"><pre class="notranslate"><code class="notranslate">---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
&lt;ipython-input-22-26ffe206b6e0&gt; in &lt;module&gt;()
----&gt; 1 model = PCA(n_components='mle').fit(X_tr)

~/.conda/envs/Science3/lib/python3.6/site-packages/sklearn/decomposition/pca.py in fit(self, X, y)
    327             Returns the instance itself.
    328         """
--&gt; 329         self._fit(X)
    330         return self
    331 

~/.conda/envs/Science3/lib/python3.6/site-packages/sklearn/decomposition/pca.py in _fit(self, X)
    382             if max(X.shape) &lt;= 500:
    383                 svd_solver = 'full'
--&gt; 384             elif n_components &gt;= 1 and n_components &lt; .8 * min(X.shape):
    385                 svd_solver = 'randomized'
    386             # This is also the case of n_components in (0,1)

TypeError: '&gt;=' not supported between instances of 'str' and 'int'
</code></pre></div>
<h1 dir="auto">Solution</h1>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="# Handle svd_solver
if n_components == 'mle':
    self.svd_solver = 'full'
svd_solver = self.svd_solver
if svd_solver == 'auto':
   # Small problem, just call full PCA
   if max(X.shape) &lt;= 500:
       svd_solver = 'full'
   elif n_components &gt;= 1 and n_components &lt; .8 * min(X.shape):
       svd_solver = 'randomized'
   # This is also the case of n_components in (0,1)
   else:
       svd_solver = 'full'"><pre class="notranslate"><code class="notranslate"># Handle svd_solver
if n_components == 'mle':
    self.svd_solver = 'full'
svd_solver = self.svd_solver
if svd_solver == 'auto':
   # Small problem, just call full PCA
   if max(X.shape) &lt;= 500:
       svd_solver = 'full'
   elif n_components &gt;= 1 and n_components &lt; .8 * min(X.shape):
       svd_solver = 'randomized'
   # This is also the case of n_components in (0,1)
   else:
       svd_solver = 'full'
</code></pre></div>
<p dir="auto"></p><div class="Box Box--condensed my-2">
  <div class="Box-header f6">
    <p class="mb-0 text-bold">
      <a href="https://github.com/scikit-learn/scikit-learn/blob/a24c8b464d094d2c468a16ea9f8bf8d42d949f84/sklearn/decomposition/pca.py#L384">scikit-learn/sklearn/decomposition/pca.py</a>
    </p>
    <p class="mb-0 color-fg-muted">
         Line 384
      in
      <a data-pjax="true" class="commit-tease-sha" href="/scikit-learn/scikit-learn/commit/a24c8b464d094d2c468a16ea9f8bf8d42d949f84">a24c8b4</a>
    </p>
  </div>
  <div itemprop="text" class="Box-body p-0 blob-wrapper blob-wrapper-embedded data">
    <table class="highlight tab-size mb-0 js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">

        <tbody><tr class="border-0">
          <td id="L384" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="384"></td>
          <td id="LC384" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-k">elif</span> <span class="pl-s1">n_components</span> <span class="pl-c1">&gt;=</span> <span class="pl-c1">1</span> <span class="pl-c1">and</span> <span class="pl-s1">n_components</span> <span class="pl-c1">&lt;</span> <span class="pl-c1">.8</span> <span class="pl-c1">*</span> <span class="pl-en">min</span>(<span class="pl-v">X</span>.<span class="pl-s1">shape</span>): </td>
        </tr>
    </tbody></table>
  </div>
</div>
<p></p>