Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CountVectorizer' object has no attribute 'get_feature_names_out'

Why do i keep getting this error? I tried different versions of anaconda 3 but did not manage to get it done. What should i install to work it properly? I used sklearn versions from 0.20 - 0.23.

Error message: enter image description here

Code:

import pandas as pd
import matplotlib.pyplot as plt
import plotly.express as px
from sklearn.feature_extraction.text import CountVectorizer
from collections import Counter
from wordcloud import WordCloud

vectorizer = CountVectorizer(ngram_range=(2,2), analyzer='word')
sparse_matrix = vectorizer.fit_transform(df['content'][:2000])
frequencies = sum(sparse_matrix).toarray()[0]
ngrams = pd.DataFrame(frequencies, index=vectorizer.get_feature_names_out(), columns=['frequency'])
ngrams = ngrams.sort_values(by='frequency', ascending=False)
ngrams
like image 917
A. Omag Avatar asked Mar 03 '26 12:03

A. Omag


1 Answers

You are using an old version of scikit-learn. If I'm not mistaken, get_feature_names_out() was only introduced in version 1.0.

Upgrade to a newer version, or, to get similar functionality in an earlier version, you can use get_feature_names().

like image 98
ozacha Avatar answered Mar 06 '26 02:03

ozacha