AttributeError: 'CountVectorizer' object has no attribute 'get_feature_names'
时间: 2023-09-18 13:16:24 浏览: 32
This error occurs when you try to call the `get_feature_names` method on a `CountVectorizer` object, but the object does not have this attribute.
One possible reason for this error is that you have not fit the `CountVectorizer` object to your data yet. The `get_feature_names` method is only available after you have called the `fit_transform` or `fit` method on the `CountVectorizer` object.
Here is an example of how to use `CountVectorizer` and call `get_feature_names` method:
```
from sklearn.feature_extraction.text import CountVectorizer
# create a CountVectorizer object
vectorizer = CountVectorizer()
# fit the vectorizer to your data
X = ['this is a sample sentence', 'another example sentence']
vectorizer.fit_transform(X)
# get the feature names
feature_names = vectorizer.get_feature_names()
print(feature_names)
```
This should output a list of the unique words in your data:
```
['another', 'example', 'is', 'sample', 'sentence', 'this']
```