<h4 dir="auto">Description</h4>

<p dir="auto">I tried to use the <code class="notranslate">learning_curve</code> function using a <code class="notranslate">Pipeline</code> object as estimator but this results in a <code class="notranslate">TypeError</code>.</p>
<h4 dir="auto">Steps/Code to Reproduce</h4>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import numpy as np
from sklearn.datasets import load_boston
from sklearn.linear_model import ElasticNet
from sklearn.model_selection import learning_curve
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler

X, y = load_boston(return_X_y=True)

pipe = Pipeline((['preproc', StandardScaler()],
                 ['predict', ElasticNet()]))

learning_curve(pipe, X, y)"><pre class="notranslate"><code class="notranslate">import numpy as np
from sklearn.datasets import load_boston
from sklearn.linear_model import ElasticNet
from sklearn.model_selection import learning_curve
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler

X, y = load_boston(return_X_y=True)

pipe = Pipeline((['preproc', StandardScaler()],
                 ['predict', ElasticNet()]))

learning_curve(pipe, X, y)
</code></pre></div>
<h4 dir="auto">Expected Results</h4>

<h4 dir="auto">Actual Results</h4>

<p dir="auto"><code class="notranslate">TypeError: 'tuple' object does not support item assignment</code></p>
<h4 dir="auto">Versions</h4>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Linux-4.4.0-96-generic-x86_64-with-debian-stretch-sid
('Python', '2.7.13 |Continuum Analytics, Inc.| (default, Dec 20 2016, 23:09:15) \n[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]')
('NumPy', '1.13.1')
('SciPy', '0.19.1')
('Scikit-Learn', '0.19.0')"><pre class="notranslate"><code class="notranslate">Linux-4.4.0-96-generic-x86_64-with-debian-stretch-sid
('Python', '2.7.13 |Continuum Analytics, Inc.| (default, Dec 20 2016, 23:09:15) \n[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]')
('NumPy', '1.13.1')
('SciPy', '0.19.1')
('Scikit-Learn', '0.19.0')
</code></pre></div>
<h4 dir="auto">Description</h4>
<p dir="auto"><code class="notranslate">TypeError: 'tuple' object does not support item assignment</code> error thrown when calling <code class="notranslate">fit</code> on a <code class="notranslate">Pipeline</code> whose <code class="notranslate">steps</code> parameter was initialized with an n-tuple (as opposed to a list) of (name, transform) tuples.</p>
<p dir="auto">Previous versions of sklearn Pipelines worked when an n-tuple was used for <code class="notranslate">steps</code>. I guess new functionality associated with Pipelines now requires that <code class="notranslate">steps</code> be mutable.</p>
<p dir="auto">I guess there are a few choices here:</p>
<ol dir="auto">
<li>Automatically handle the case of an n-tuple being passed by creating a new list for <code class="notranslate">self.steps</code> and copying over the tuple's items to it. And maybe throw a warning for behavior's deprecation.</li>
<li>Throw an immediate error during initialization if <code class="notranslate">steps</code> is a tuple. Of course, this is still a breaking change, but at least, the user won't have to wait until calling <code class="notranslate">fit</code> before discovering something is wrong.</li>
</ol>
<p dir="auto">I could submit a PR for this if you want.</p>
<h4 dir="auto">Steps/Code to Reproduce</h4>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="from sklearn.pipeline import Pipeline
from sklearn.ensemble import RandomForestClassifier
from sklearn.decomposition import PCA
from sklearn.datasets import load_breast_cancer

pipeline = Pipeline((('pca', PCA()), ('rf', RandomForestClassifier())))
X, y = load_breast_cancer(True)
pipeline.fit(X, y)"><pre class="notranslate"><span class="pl-k">from</span> <span class="pl-s1">sklearn</span>.<span class="pl-s1">pipeline</span> <span class="pl-k">import</span> <span class="pl-v">Pipeline</span>
<span class="pl-k">from</span> <span class="pl-s1">sklearn</span>.<span class="pl-s1">ensemble</span> <span class="pl-k">import</span> <span class="pl-v">RandomForestClassifier</span>
<span class="pl-k">from</span> <span class="pl-s1">sklearn</span>.<span class="pl-s1">decomposition</span> <span class="pl-k">import</span> <span class="pl-v">PCA</span>
<span class="pl-k">from</span> <span class="pl-s1">sklearn</span>.<span class="pl-s1">datasets</span> <span class="pl-k">import</span> <span class="pl-s1">load_breast_cancer</span>

<span class="pl-s1">pipeline</span> <span class="pl-c1">=</span> <span class="pl-v">Pipeline</span>(((<span class="pl-s">'pca'</span>, <span class="pl-v">PCA</span>()), (<span class="pl-s">'rf'</span>, <span class="pl-v">RandomForestClassifier</span>())))
<span class="pl-v">X</span>, <span class="pl-s1">y</span> <span class="pl-c1">=</span> <span class="pl-en">load_breast_cancer</span>(<span class="pl-c1">True</span>)
<span class="pl-s1">pipeline</span>.<span class="pl-en">fit</span>(<span class="pl-v">X</span>, <span class="pl-s1">y</span>)</pre></div>
<h4 dir="auto">Expected Results</h4>

<p dir="auto">This had no errors in previous versions</p>
<h4 dir="auto">Actual Results</h4>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
  File &quot;/usr/local/lib/python2.7/dist-packages/sklearn/pipeline.py&quot;, line 257, in fit
    Xt, fit_params = self._fit(X, y, **fit_params)
  File &quot;/usr/local/lib/python2.7/dist-packages/sklearn/pipeline.py&quot;, line 226, in _fit
    self.steps[step_idx] = (name, fitted_transformer)
TypeError: 'tuple' object does not support item assignment
"><pre class="notranslate"><code class="notranslate">Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "/usr/local/lib/python2.7/dist-packages/sklearn/pipeline.py", line 257, in fit
    Xt, fit_params = self._fit(X, y, **fit_params)
  File "/usr/local/lib/python2.7/dist-packages/sklearn/pipeline.py", line 226, in _fit
    self.steps[step_idx] = (name, fitted_transformer)
TypeError: 'tuple' object does not support item assignment

</code></pre></div>
<h4 dir="auto">Versions</h4>

<p dir="auto">Linux-4.4.0-36-generic-x86_64-with-Ubuntu-14.04-trusty<br>
('Python', '2.7.6 (default, Jun 22 2015, 17:58:13) \n[GCC 4.8.2]')<br>
('NumPy', '1.13.1')<br>
('SciPy', '0.19.0')<br>
('Scikit-Learn', '0.19.0')</p>