<h4 dir="auto">Description</h4>
<p dir="auto">If I create a OneHotEncoder instance defining the categories manually and then try to transform data directly (skipping the fitting step), I get a NotFittedError.</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.preprocessing import OneHotEncoder
categories = ['a', 'b', 'c']
ohe = OneHotEncoder(categories=categories)
new = ohe.transform(['a', 'c', 'b', 'b'])"><pre class="notranslate"><code class="notranslate">import numpy as np
from sklearn.preprocessing import OneHotEncoder
categories = ['a', 'b', 'c']
ohe = OneHotEncoder(categories=categories)
new = ohe.transform(['a', 'c', 'b', 'b'])
</code></pre></div>
<h4 dir="auto">Expected Results</h4>
<p dir="auto">No error, since the categories were defined manually. This is the behaviour that I expected from the documentation:</p>
<blockquote>
<p dir="auto">By default, the encoder derives the categories based on the unique values in each feature. Alternatively, you can also specify the categories manually.</p>
</blockquote>
<h4 dir="auto">Actual Results</h4>
<blockquote>
<hr>
<p dir="auto">NotFittedError                            Traceback (most recent call last)<br>
 in <br>
3 categories = ['a', 'b', 'c']<br>
4 ohe = OneHotEncoder(categories=categories)<br>
----&gt; 5 new = ohe.transform(['a', 'c', 'b', 'b'])</p>
<p dir="auto">~\AppData\Local\Continuum\anaconda3\lib\site-packages\sklearn\preprocessing_encoders.py in transform(self, X)<br>
724             Transformed input.<br>
725         """<br>
--&gt; 726         check_is_fitted(self, 'categories_')<br>
727         if self._legacy_mode:<br>
728             return _transform_selected(X, self._legacy_transform, self.dtype,</p>
<p dir="auto">~\AppData\Local\Continuum\anaconda3\lib\site-packages\sklearn\utils\validation.py in check_is_fitted(estimator, attributes, msg, all_or_any)<br>
912<br>
913     if not all_or_any([hasattr(estimator, attr) for attr in attributes]):<br>
--&gt; 914         raise NotFittedError(msg % {'name': type(estimator).<strong>name</strong>})<br>
915<br>
916</p>
<p dir="auto">NotFittedError: This OneHotEncoder instance is not fitted yet. Call 'fit' with appropriate arguments before using this method.</p>
</blockquote>

<h4 dir="auto">Versions</h4>
<p dir="auto">Windows-10-10.0.17134-SP0<br>
Python 3.7.3 (default, Apr 24 2019, 15:29:51) [MSC v.1915 64 bit (AMD64)]<br>
NumPy 1.16.4<br>
SciPy 1.2.1<br>
Scikit-Learn 0.21.2</p>
<p dir="auto">Right now there's some estimators that don't require calling "fit", two that I'm aware of: <code class="notranslate">Normalizer</code> and <code class="notranslate">FunctionTransformer</code>. They do input validation if <code class="notranslate">fit</code> is called.<br>
There's one estimator that is stateless but requires calling <code class="notranslate">fit</code> for no real reason I can see, <code class="notranslate">AdditiveChi2Sampler</code>.</p>
<p dir="auto">My questions are:</p>
<ul dir="auto">
<li>
<p dir="auto">Should we remove the requirement to calling <code class="notranslate">fit</code> if it can be avoided?</p>
</li>
<li>
<p dir="auto">If <code class="notranslate">fit</code> is called, should we ensure that the number of features is the same in <code class="notranslate">fit</code> and <code class="notranslate">transform</code>, even though that's not required by the algorithm to avoid user errors?</p>
</li>
</ul>