Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes error of get_feature_names removal #235

Merged

Conversation

David-Moody
Copy link
Contributor

Error when using scikit-learn >= 1.2.0

pyLDAvis.sklearn.prepare raises an error due to a missing method get_feature_names() for the vectorizer argument.

AttributeError: 'CountVectorizer' object has no attribute 'get_feature_names'

Using the documentation of sklearn.feature_extraction.text.CountVectorizer as an example. It can be seen this function was deprecated in 1.0 docs, and removed in 1.2 docs. The same is true for the other vectorizer that can be used TfidfVectorizer.

The recommendation in those docs is to use get_feature_names_out() as a replacement.

Instead of returning a list of feature names, this now returns an ndarray of them. Though both being iterable types it makes no difference for the use case, where reference is only required to array-like.

This fix would also be backwards compatible to at least scikit-learn 1.0.

Tested on a fresh conda environment with Python==3.10.8, and gives expected behaviour.

@zhfuch
Copy link

zhfuch commented Jan 9, 2023

Error when using scikit-learn >= 1.2.0

pyLDAvis.sklearn.prepare raises an error due to a missing method get_feature_names() for the vectorizer argument.

AttributeError: 'CountVectorizer' object has no attribute 'get_feature_names'

Using the documentation of sklearn.feature_extraction.text.CountVectorizer as an example. It can be seen this function was deprecated in 1.0 docs, and removed in 1.2 docs. The same is true for the other vectorizer that can be used TfidfVectorizer.

The recommendation in those docs is to use get_feature_names_out() as a replacement.

Instead of returning a list of feature names, this now returns an ndarray of them. Though both being iterable types it makes no difference for the use case, where reference is only required to array-like.

This fix would also be backwards compatible to at least scikit-learn 1.0.

Tested on a fresh conda environment with Python==3.10.8, and gives expected behaviour.

Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants