當前位置: 首頁>>代碼示例>>Python>>正文


Python TfidfVectorizer._validate_vocabulary方法代碼示例

本文整理匯總了Python中sklearn.feature_extraction.text.TfidfVectorizer._validate_vocabulary方法的典型用法代碼示例。如果您正苦於以下問題:Python TfidfVectorizer._validate_vocabulary方法的具體用法?Python TfidfVectorizer._validate_vocabulary怎麽用?Python TfidfVectorizer._validate_vocabulary使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sklearn.feature_extraction.text.TfidfVectorizer的用法示例。


在下文中一共展示了TfidfVectorizer._validate_vocabulary方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: vectorize_words

# 需要導入模塊: from sklearn.feature_extraction.text import TfidfVectorizer [as 別名]
# 或者: from sklearn.feature_extraction.text.TfidfVectorizer import _validate_vocabulary [as 別名]
	def vectorize_words(self, clean_profiles, max_features = 500) :
		# Vectorize the words in the cleaned profiles using 
		# term frequency/inverse document frequency (TF-IDF)
		print "Creating the bag of words...\n"

		# Initialize the "CountVectorizer" object, which is scikit-learn's
		# bag of words tool.  
		vectorizer = TfidfVectorizer(min_df=1, max_features = max_features) 
		vectorizer._validate_vocabulary()

		# fit_transform() does two functions: First, it fits the model
		# and learns the vocabulary; second, it transforms our training data
		# into feature vectors. The input to fit_transform should be a list of 
		# strings.
		data_features = vectorizer.fit_transform(clean_profiles)

		# Numpy arrays are easy to work with, so convert the result to an 
		# array
		data_features = data_features.toarray()
		print data_features.shape

		vocab = vectorizer.get_feature_names()

		# Sum up the counts of each vocabulary word
		dist = np.sum(data_features, axis=0)

	
		return vectorizer, data_features, vocab, dist
開發者ID:gshattow,項目名稱:meditweeter,代碼行數:30,代碼來源:bag_of_words.py


注:本文中的sklearn.feature_extraction.text.TfidfVectorizer._validate_vocabulary方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。