python scikit-learn TfidfVectorizer: why ValueError when input is 2 single-character strings?
<p>I am trying to run something like this:</p>

<pre><code>from sklearn.feature_extraction.text import TfidfVectorizer

test_text = ["q", "r"]

vect = TfidfVectorizer(min_df=1,
                       stop_words=None, 
                       lowercase=False) 
tfidf = vect.fit_transform(test_text)

print vect.get_feature_names()
</code></pre>

<p>But get a ValueError:</p>

<p><code>ValueError: empty vocabulary; perhaps the documents only contain stop words</code></p>

<p>Does guidance exist on what limitations or constraints for the input are? I was not able to find anything on the <a href="http://scikit-learn.org/stable/modules/generated/sklearn.feature_extraction.text.TfidfVectorizer.html" rel="nofollow">TfidfVectorizer doc page</a>. I tried to trace it, and got to the <code>_count_vocab</code> function, but I have trouble reading it. Also, when I change the strings to length 2 or more, code runs fine.</p>

<p>The error is because of the min_df parameter. When you set the value of min_df =0, it will work fine as it will not be bounded by the 'minimum threshold' which is currently set to 1 and each of your word also appears for once only.</p>

python scikit-learn nlp tf-idf