Python으로 배우는 NLP 피처 엔지니어링
Rounak Banik
Data Scientist
human이 5번 등장합니다.human에 해당하는 차원의 가중치는 5입니다.jupiter와 universe가 각각 20회 등장합니다.jupiter는 드뭅니다. universe는 흔합니다.jupiter에 더 높은 가중치를 부여합니다.$$\red{w_{i,j}} = tf_{i,j} \cdot \log\left(\frac{N}{df_{i}}\right) $$
$$\red{w_{i,j}} \rightarrow \text{문서 } j \text{에서 용어 } i \text{의 가중치}$$
$$w_{i,j} = \red{tf_{i,j}} \cdot \log\left(\frac{N}{df_{i}}\right) $$
$$w_{i,j} \rightarrow \text{문서 } j \text{에서 용어 } i \text{의 가중치}$$
$$\red{tf_{i,j}} \rightarrow \text{문서 } j \text{에서 용어 } i \text{의 빈도} $$
$$w_{i,j} = tf_{i,j} \cdot \red{\log\left(\frac{N}{df_{i}}\right)} $$
$$w_{i,j} \rightarrow \text{문서 } j \text{에서 용어 } i \text{의 가중치}$$
$$tf_{i,j} \rightarrow \text{문서 } j \text{에서 용어 } i \text{의 빈도} $$
$$\red{N} \rightarrow \text{코퍼스의 문서 수} $$
$$\red{df_{i}} \rightarrow \text{용어 } i \text{가 포함된 문서 수}$$
$$w_{i,j} = tf_{i,j} \cdot \log\left(\frac{N}{df_{i}}\right) $$
$$w_{i,j} \rightarrow \text{문서 } j \text{에서 용어 } i \text{의 가중치}$$
$$tf_{i,j} \rightarrow 문서 \; j \; 에서 \; 용어 \; i \; 의 \; 빈도 $$
$$N \rightarrow 코퍼스 \; 내 \; 문서 \; 수 $$
$$df_{i} \rightarrow 용어 \; i \; 를 \; 포함한 \; 문서 \; 수 $$
예:
$\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. ]
...
Python으로 배우는 NLP 피처 엔지니어링