本文整理匯總了Python中sklearn.feature_extraction.text.TfidfVectorizer.stop_words方法的典型用法代碼示例。如果您正苦於以下問題:Python TfidfVectorizer.stop_words方法的具體用法?Python TfidfVectorizer.stop_words怎麽用?Python TfidfVectorizer.stop_words使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sklearn.feature_extraction.text.TfidfVectorizer
的用法示例。
在下文中一共展示了TfidfVectorizer.stop_words方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: vectorizaCorpus
# 需要導入模塊: from sklearn.feature_extraction.text import TfidfVectorizer [as 別名]
# 或者: from sklearn.feature_extraction.text.TfidfVectorizer import stop_words [as 別名]
def vectorizaCorpus(corpus, minDf):
''' Vectoriza o corpus introducido filtrando as palabras que aparecen en
menos de minDf documentos'''
try:
vectorizer = TfidfVectorizer(min_df = minDf, lowercase=True, stop_words='english')
# Definimos unha lista propoia de stopwords
myStopwords = ['did','didn','does','doesn','don','just','isn', \
'reddit', 'wasn','www','yeah','yes','like','able','thanks', \
'know', 'think','ve', 'want','com','https','http',\
'good', 'really', 'make', 'say', 'going', 'said', 'people','way', \
'use']
# engadimos as stop_words que queremos ao conxunto xa existente
vectorizer.stop_words = vectorizer.get_stop_words().union(myStopwords)
# calculamos a matriz de documentos-términos
docTerms = vectorizer.fit_transform(corpus)
# invertimos o vocabulario creando un diccionario de índices - termos
invVoc = {v: k for k, v in vectorizer.vocabulary_.items()}
# buscamos os termos centrais, que son os que a suma acumulada de tf/idf en todos os documentos é maior
sumaTfidf = docTerms.sum(axis=0).tolist()[0] #calculamos a suma por columnas da matriz de documentos-termos
return vectorizer, invVoc, sumaTfidf
except Exception as e:
print('\nOcorreu un problema: {0}'.format(e))
sys.exit()