<p dir="auto">I saw the below code used in several places so that <code class="notranslate">LabelBinarizer()</code> can be used within pipeline. Can it be added as a part of sklearn default?</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="from sklearn.preprocessing import LabelBinarizer

class LabelBinarizerPipelineFriendly(LabelBinarizer):
    def fit(self, X, y=None):
        &quot;&quot;&quot;this would allow us to fit the model based on the X input.&quot;&quot;&quot;
        super(LabelBinarizerPipelineFriendly,self).fit(X)
    def transform(self, X, y=None):
        return super(LabelBinarizerPipelineFriendly, self).transform(X)
    def fit_transform(self, X, y=None):
        return super(LabelBinarizerPipelineFriendly, self).fit(X).transform(X)"><pre class="notranslate"><span class="pl-k">from</span> <span class="pl-s1">sklearn</span>.<span class="pl-s1">preprocessing</span> <span class="pl-k">import</span> <span class="pl-v">LabelBinarizer</span>

<span class="pl-k">class</span> <span class="pl-v">LabelBinarizerPipelineFriendly</span>(<span class="pl-v">LabelBinarizer</span>):
    <span class="pl-k">def</span> <span class="pl-en">fit</span>(<span class="pl-s1">self</span>, <span class="pl-v">X</span>, <span class="pl-s1">y</span><span class="pl-c1">=</span><span class="pl-c1">None</span>):
        <span class="pl-s">"""this would allow us to fit the model based on the X input."""</span>
        <span class="pl-en">super</span>(<span class="pl-v">LabelBinarizerPipelineFriendly</span>,<span class="pl-s1">self</span>).<span class="pl-en">fit</span>(<span class="pl-v">X</span>)
    <span class="pl-k">def</span> <span class="pl-en">transform</span>(<span class="pl-s1">self</span>, <span class="pl-v">X</span>, <span class="pl-s1">y</span><span class="pl-c1">=</span><span class="pl-c1">None</span>):
        <span class="pl-k">return</span> <span class="pl-en">super</span>(<span class="pl-v">LabelBinarizerPipelineFriendly</span>, <span class="pl-s1">self</span>).<span class="pl-en">transform</span>(<span class="pl-v">X</span>)
    <span class="pl-k">def</span> <span class="pl-en">fit_transform</span>(<span class="pl-s1">self</span>, <span class="pl-v">X</span>, <span class="pl-s1">y</span><span class="pl-c1">=</span><span class="pl-c1">None</span>):
        <span class="pl-k">return</span> <span class="pl-en">super</span>(<span class="pl-v">LabelBinarizerPipelineFriendly</span>, <span class="pl-s1">self</span>).<span class="pl-en">fit</span>(<span class="pl-v">X</span>).<span class="pl-en">transform</span>(<span class="pl-v">X</span>)</pre></div>
<p dir="auto">The problem is that LabelBinarizer()'s functions take one parameter, while they should take the <code class="notranslate">X, y = None</code> params. I undestand that this would lead to changing interface (=major change), but it seems to be reasonable and consistent with the general interface.</p>
<p dir="auto">I get this error when I try to use <code class="notranslate">LabelBinarizer</code> and <code class="notranslate">LabelEncoder</code> in a Pipeline:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="sklearn/pipeline.pyc in fit_transform(self, X, y, **fit_params)
    141         Xt, fit_params = self._pre_transform(X, y, **fit_params)
    142         if hasattr(self.steps[-1][-1], 'fit_transform'):
--&gt; 143             return self.steps[-1][-1].fit_transform(Xt, y, **fit_params)
    144         else:
    145             return self.steps[-1][-1].fit(Xt, y, **fit_params).transform(Xt)

TypeError: fit_transform() takes exactly 2 arguments (3 given)"><pre class="notranslate"><span class="pl-s1">sklearn</span><span class="pl-c1">/</span><span class="pl-s1">pipeline</span>.<span class="pl-s1">pyc</span> <span class="pl-c1">in</span> <span class="pl-en">fit_transform</span>(<span class="pl-s1">self</span>, <span class="pl-v">X</span>, <span class="pl-s1">y</span>, <span class="pl-c1">**</span><span class="pl-s1">fit_params</span>)
    <span class="pl-c1">141</span>         <span class="pl-v">Xt</span>, <span class="pl-s1">fit_params</span> <span class="pl-c1">=</span> <span class="pl-s1">self</span>.<span class="pl-en">_pre_transform</span>(<span class="pl-v">X</span>, <span class="pl-s1">y</span>, <span class="pl-c1">**</span><span class="pl-s1">fit_params</span>)
    <span class="pl-c1">142</span>         <span class="pl-k">if</span> <span class="pl-en">hasattr</span>(<span class="pl-s1">self</span>.<span class="pl-s1">steps</span>[<span class="pl-c1">-</span><span class="pl-c1">1</span>][<span class="pl-c1">-</span><span class="pl-c1">1</span>], <span class="pl-s">'fit_transform'</span>):
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">143</span>             <span class="pl-s1">return</span> <span class="pl-s1">self</span>.<span class="pl-s1">steps</span>[<span class="pl-c1">-</span><span class="pl-c1">1</span>][<span class="pl-c1">-</span><span class="pl-c1">1</span>].<span class="pl-en">fit_transform</span>(<span class="pl-v">Xt</span>, <span class="pl-s1">y</span>, <span class="pl-c1">**</span><span class="pl-s1">fit_params</span>)
    <span class="pl-c1">144</span>         <span class="pl-k">else</span>:
    <span class="pl-c1">145</span>             <span class="pl-s1">return</span> <span class="pl-s1">self</span>.<span class="pl-s1">steps</span>[<span class="pl-c1">-</span><span class="pl-c1">1</span>][<span class="pl-c1">-</span><span class="pl-c1">1</span>].<span class="pl-en">fit</span>(<span class="pl-v">Xt</span>, <span class="pl-s1">y</span>, <span class="pl-c1">**</span><span class="pl-s1">fit_params</span>).<span class="pl-en">transform</span>(<span class="pl-v">Xt</span>)

<span class="pl-v">TypeError</span>: <span class="pl-en">fit_transform</span>() <span class="pl-s1">takes</span> <span class="pl-s1">exactly</span> <span class="pl-c1">2</span> <span class="pl-s1">arguments</span> (<span class="pl-c1">3</span> <span class="pl-s1">given</span>)</pre></div>
<p dir="auto">It seems like this is because the classes' <a href="https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/label.py#L85"><code class="notranslate">fit</code> and <code class="notranslate">transform</code> signatures</a> are different from most other estimators and only accept a single argument.</p>
<p dir="auto">I think this is a pretty easy fix (just change the signature to <code class="notranslate">def(self, X, y=None)</code>) that I'd be happy to send a pull request for, but I wanted to check if there were any other reasons that the signatures are the way they are that I didn't think of.</p>