擅长:python、mysql、java
<p>在最后一步中,不能对包含非转换器的管道调用转换方法。
如果您不想在这样的管道上调用transfrom,最后一个估计器必须是一个转换器。在</p>
<p>即使是方法医生也这么说:</p>
<blockquote>
<p>Applies transforms to the data, and the transform method of the
final estimator. Valid only if the final estimator implements
<strong>transform</strong>.</p>
</blockquote>
<p>此外,除了最后一个估计量外,并没有任何方法可以使用每一个估计量。
您可以创建自己的管道,并从scikit learn的管道中继承所有内容,但添加一个方法,例如:</p>
<pre><code>def just_transforms(self, X):
"""Applies all transforms to the data, without applying last
estimator.
Parameters
X : iterable
Data to predict on. Must fulfill input requirements of first step of
the pipeline.
"""
Xt = X
for name, transform in self.steps[:-1]:
Xt = transform.transform(Xt)
return Xt
</code></pre>