Issue
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:
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
Solution
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()
.
Answered By - ozacha
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.