CountVectorizer default token pattern defines underscore as a letter
corpus = ['The rain in spain_stays' ]
vectorizer = CountVectorizer(token_pattern=r'(?u)\b\w\w+\b')
X = vectorizer.fit_transform(corpus)
print(vectorizer.get_feature_names())
gives:
['in', 'rain', 'spain_stays', 'the']
this makes sense since AFAIK '/w' is eqivilent to [a-zA-z0-9_], what I need is:
['in', 'rain', 'spain', 'stays', 'the']
so I tried replacing the '/w' with [a-zA-Z0-9]
vectorizer = CountVectorizer(token_pattern=r'(?u)\b[a-zA-Z0-9][a-zA-Z0-9]+\b')
X = vectorizer.fit_transform(corpus)
print(vectorizer.get_feature_names())
but I get
['in', 'rain', 'the']
How can I get what I need? any ideas are welcome