Back to questions
JuniorTheoryCommon
What does this program print?
from sklearn.feature_extraction.text import CountVectorizer
vec = CountVectorizer()
vec.fit(["red apple", "green apple"])
X = vec.transform(["Red red pear!"])
print(X.shape[1], X.sum())3 2
- Expecting
4 3:transformkeeps the vocabulary learned byfit, sopeargets no column and is dropped. - Expecting
3 1:CountVectorizerlowercases text by default, so bothRedandredare counted in theredcolumn.
- What goes wrong if you call
fit_transformon the new texts instead oftransform? - Why does
CountVectorizerreturn a sparse matrix rather than a numpy array?