私はPythonを使用していますが、大量のデータのTFIDF表現を取得するには、次のコードを使用してドキュメントをTFIDF形式に変換します。選択されたフィーチャー名を取得するTFIDFベクトル化ツール
from sklearn.feature_extraction.text import TfidfVectorizer
tfidf_vectorizer = TfidfVectorizer(
min_df=1, # min count for relevant vocabulary
max_features=4000, # maximum number of features
strip_accents='unicode', # replace all accented unicode char
# by their corresponding ASCII char
analyzer='word', # features made of words
token_pattern=r'\w{1,}', # tokenize only words of 4+ chars
ngram_range=(1, 1), # features made of a single tokens
use_idf=True, # enable inverse-document-frequency reweighting
smooth_idf=True, # prevents zero division for unseen words
sublinear_tf=False)
tfidf_df = tfidf_vectorizer.fit_transform(df['text'])
ここでは、パラメータmax_features
を渡します。ベクタライザは、最高の機能を選択して、疎のマトリックスを返します。問題はどの機能が選択されているのか分からず、これらの機能名を私が入手したscipyマトリックスにどのようにマップするのですか?基本的にm
個のドキュメントのn
の選択されたフィーチャの場合、選択されたフィーチャを持つm x n
マトリックスを、その整数IDではなく列名として使用します。これをどのように達成するのですか?
'vocabulary_'属性は、変換された行列ではなく、ベクトル化された行列のためのものです。 –
はい、それはタイプミスでした。 –