class sklearn.feature_extraction.text.TfidfVectorizer(input=’content’, encoding=’utf-8’, decode_error=’strict’, strip_accents=None, lowercase=True, preprocessor=None, tokenizer=None, analyzer=’word’, stop_words=None, token_pattern=’(?u)\b\w\w+\b’, ngram_range=(1, 1), max_df=1.0, min_df=1, max_features=None, vocabulary=None, binary=False, dtype=<class ‘numpy.int64’>, norm=’l2’, use_idf=True, smooth_idf=True, sublinear_tf=False)
調用方法:from sklearn.feature_extraction.text import TfidfVectorizer
將原始文本集轉換爲TFIDF向量矩陣,相當於先進行文本向量化再進行TDIDF化。
參數說明:
1, input : string {‘filename’, ‘file’, ‘content’}
可以是需要處理的文件名稱列表(filename),也可以是具體的一個文件(file),也可以是字符串(content)
2,encoding : string, ‘utf-8’ by default.
編碼方式,說明輸入文件的編碼方式,默認爲utf-8
3,decode_error : {‘strict’, ‘ignore’, ‘replace’}
4,strip_accents : {‘ascii’, ‘unicode’, None}
5,analyzer : string, {‘word’, ‘char’} or callable
6,preprocessor : callable or None (default)
7,tokenizer : callable or None (default)
8,ngram_range : tuple (min_n, max_n)
9,stop_words : string {‘english’}, list, or None (default)
10,lowercase : boolean, default True
11,token_pattern : string
12,max_df : float in range [0.0, 1.0] or int, default=1.0
詞頻上限,當輸入整數值時不考慮出現次數多於給定次數的詞,當輸入0到1的浮點數值時看作詞彙在文檔中所佔比例上限,如果前面給定了詞典,這一參數將被忽略。
13,min_df : float in range [0.0, 1.0] or int, default=1
詞頻下限,當輸入整數值時不考慮出現次數少於給定次數的詞,當輸入0到1的浮點數值時看作詞彙在文檔中所佔比例下限,如果前面給定了詞典,這一參數將被忽略。
14,max_features : int or None, default=None
15,vocabulary : Mapping or iterable, optional
16,binary : boolean, default=False
17,dtype : type, optional
18,norm : ‘l1’, ‘l2’ or None, optional
19,use_idf : boolean, default=True
20,smooth_idf : boolean, default=True
21,sublinear_tf : boolean, default=False
方法使用說明:
1,build_analyzer()
2,build_preprocessor()
3,build_tokenizer()
4,decode(doc)
5,fit(raw_documents[, y])
fit_transform(raw_documents, y=None)
6,fit_transform(raw_documents[, y])
7,get_feature_names()
8,get_params([deep])
10,inverse_transform(X)
11,set_params(**params)
12,transform(raw_documents[, copy])