728x90
오류
토픽 모델링 예제 실습 중 'TfidfVectorizer' object has no attribute 'get_feature_names'라는 오류가 발생했다.
해결방법
get_feature_names를 get_feature_names_out()로 변경한다.
# sklearn 버전 이슈로 메서드 변경
terms = vectorizer.get_feature_names_out()
# 각 20개 행의 1,000개 열 중 가장 값이 큰 5개를 찾아서 단어로 출력
def get_topics(components, feature_names, n=5):
for idx, topic in enumerate(components):
print("Topic %d:" % (idx+1), [(feature_names[i], topic[i].round(5)) for i in topic.argsort()[:-n - 1:-1]])
get_topics(svd_model.components_,terms)
📌 참고. https://noanomal.tistory.com/461
AttributeError: 'TfidfVectorizer' object has no attribute 'get_feature_names'
AttributeError: 'TfidfVectorizer' object has no attribute 'get_feature_names' get_feature_names()는 sklearn 0.24 버전 이하에서 사용하던 메서드 입니다. 1.0 버전 부터는 get_feature_names_out()로 변경되었습니다. get_feature_names
noanomal.tistory.com
728x90
'Study > Python' 카테고리의 다른 글
[Python] ChatGPT 앱 Appstore, Google Playstore 리뷰 크롤링(App ID 확인하기) (1) | 2024.12.19 |
---|---|
[Python] Google Colab 단축키 (0) | 2024.06.04 |
[Python] 문자열 slice (0) | 2024.03.20 |
[Python] enumerate 함수(with 프로그래머스>부분 문자열 이어 붙여 문자열 만들기) (0) | 2024.03.20 |
[Python] endswith 함수(with 프로그래머스>접미사인지 확인하기) (0) | 2024.03.20 |