Rekayasa Fitur untuk NLP di Python
Rounak Banik
Data Scientist
human di lima tempat.human berbobot 5.jupiter dan universe masing-masing muncul 20 kali.jupiter jarang muncul di dokumen lain. universe umum.jupiter karena kekhasan.$$\red{w_{i,j}} = tf_{i,j} \cdot \log\left(\frac{N}{df_{i}}\right) $$
$$\red{w_{i,j}} \rightarrow \text{bobot istilah } i \text{ dalam dokumen } j$$
$$w_{i,j} = \red{tf_{i,j}} \cdot \log\left(\frac{N}{df_{i}}\right) $$
$$w_{i,j} \rightarrow \text{bobot istilah } i \text{ dalam dokumen } j$$
$$\red{tf_{i,j}} \rightarrow \text{frekuensi istilah untuk istilah } i \text{ dalam dokumen } j $$
$$w_{i,j} = tf_{i,j} \cdot \red{\log\left(\frac{N}{df_{i}}\right)} $$
$$w_{i,j} \rightarrow \text{bobot istilah } i \text{ dalam dokumen } j$$
$$tf_{i,j} \rightarrow \text{frekuensi istilah untuk istilah } i \text{dalam dokumen } j $$
$$\red{N} \rightarrow \text{jumlah dokumen dalam korpus } $$
$$\red{df_{i}} \rightarrow \text{jumlah dokumen yang memuat istilah } i$$
$$w_{i,j} = tf_{i,j} \cdot \log\left(\frac{N}{df_{i}}\right) $$
$$w_{i,j} \rightarrow \text{bobot istilah } i \text{ dalam dokumen } j$$
$$tf_{i,j} \rightarrow term \; frequency \; of \; term \; i \; in \; document \; j $$
$$N \rightarrow number \; of \; documents \; in \; the \; corpus $$
$$df_{i} \rightarrow number \; of \; documents \; cotaining \; term \; i$$
Contoh:
$\red{w_{library, document}} = 5 \cdot log(\frac{20}{8}) \approx 2 $
# Import TfidfVectorizer from sklearn.feature_extraction.text import TfidfVectorizer# Create TfidfVectorizer object vectorizer = TfidfVectorizer()# Generate matrix of word vectors tfidf_matrix = vectorizer.fit_transform(corpus) print(tfidf_matrix.toarray())
[[0. 0. 0. 0. 0.25434658 0.33443519
0.33443519 0. 0.25434658 0. 0.25434658 0.
0.76303975]
[0. 0.46735098 0. 0.46735098 0. 0.
0. 0.46735098 0. 0.46735098 0.35543247 0.
0. ]
...
Rekayasa Fitur untuk NLP di Python