2016-12-23 3 views
0

안녕하세요 나는 다음과 같은 목록을 다음과 같이 내 의견에서 모델을 얻을 수있는 TFIDF의 벡터화를 만들어 다음 tfidf 모델에서 가장 대표적인 기능을 얻는 방법은 무엇입니까?

listComments = ["comment1","comment2","comment3",...,"commentN"] 

:

이제
tfidf_vectorizer = TfidfVectorizer(min_df=10,ngram_range=(1,3),analyzer='word') 
tfidf = tfidf_vectorizer.fit_transform(listComments) 

싶습니다 내 모델에 대한 자세한 내용을 알아 보았하기 위해 가장 대표적인 기능을 얻으려고 시도 :

print("these are the features :",tfidf_vectorizer.get_feature_names()) 
print("the vocabulary :",tfidf_vectorizer.vocabulary_) 

그리고 내 모델이 ve에 사용하는 단어 목록을 제공합니다. ctorization :

these are the features : ['10', '10 days', 'red', 'car',...] 

the vocabulary : {'edge': 86, 'local': 96, 'machine': 2,...} 

나는 30 개 가장 대표적인 기능을 얻을 수있는 방법을 찾기 위해 싶습니다 그러나, 나는 내 TFIDF 모델에서 가장 높은 값을 달성 단어, 가장 높은 역 frecuency과 함께, 내가에서 읽고 있던 단어를 의미 문서하지만 난 정말이 문제에 도움을 주셔서 감사합니다이 방법을 사전에 감사합니다, 당신은 IDF 점수에 대한 어휘의 목록을 얻고 싶다면

답변

1

당신이 idf_ 속성과 argsort을 사용할 수를 찾을 수 없습니다 그것.

# create an array of feature names 
feature_names = np.array(tfidf_vectorizer.get_feature_names()) 

# get order 
idf_order = tfidf_vectorizer.idf_.argsort()[::-1] 

# produce sorted idf word 
feature_names[idf_order] 

각 문서에 대해 tfidf 점수의 정렬 된 목록을 얻고 싶다면 비슷한 일을 할 것입니다.

# get order for all documents based on tfidf scores 
tfidf_order = tfidf.toarray().argsort()[::-1] 

# produce words 
feature_names[tfidf_order] 
+0

감사합니다. 정말 고맙습니다. – neo33

관련 문제