Python में NLP के लिए Feature Engineering
Rounak Banik
Data Scientist
human शब्द 5 जगह है।human वाले डायमेंशन का वेट 5 है।jupiter और universe 20-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{टर्म } i \text{ का डॉक्यूमेंट } j \text{ में वेट}$$
$$w_{i,j} = \red{tf_{i,j}} \cdot \log\left(\frac{N}{df_{i}}\right) $$
$$w_{i,j} \rightarrow \text{टर्म } i \text{ का डॉक्यूमेंट } j \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{टर्म } i \text{ का डॉक्यूमेंट } j \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{टर्म } i \text{ का डॉक्यूमेंट } j \text{ में वेट} $$
$$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$$
उदाहरण:
$\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 के लिए Feature Engineering