How to get number of dimensions in OneHotEncoder in Scikit-learn
<p>I am using the <a href="http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.OneHotEncoder.html" rel="nofollow"><code>OneHotEncoder</code></a> from Scikit-learn in my project. And I need to know what would be the size of each one-hot vector when the <code>n_value</code> is set to be <code>auto</code>. I thought <code>n_value_</code> would show that but it seems I have no way other than trying out training samples. I made this toy example code to show the problem. Do you know any other solution?</p>

<pre><code>from sklearn.preprocessing import OneHotEncoder

data = [[1], [3], [5]] # 3 different features

encoder = OneHotEncoder()
encoder.fit(data)

print(len(encoder.transform([data[0]]).toarray()[0])) # 3 number of dimensions in one-hot-vector
print(encoder.n_values_) # [6] == len(range(5))
</code></pre>

<p>Is this what you are looking for?</p>

<pre><code>&gt;&gt;&gt; encoder.active_features_
array([1, 3, 5])

&gt;&gt;&gt; len(encoder.active_features_)
3
</code></pre>

python machine-learning scikit-learn one-hot-encoding