๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Study/Python

[Python] Google Colab์—์„œ 'TfidfVectorizer' object has no attribute 'get_feature_names' Error ํ•ด๊ฒฐํ•˜๊ธฐ

by zyhu_n 2024. 5. 31.

๐Ÿ”ฅ ์˜ค๋ฅ˜

 

ํ† ํ”ฝ ๋ชจ๋ธ๋ง ์˜ˆ์ œ ์‹ค์Šต ์ค‘ '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