Bag-of-words

Sentiment Analysis ด้วย Python

Violeta Misheva

Data Scientist

Bag-of-words (BOW) คืออะไร?

 

  • อธิบายการปรากฏของคำในเอกสารหนึ่งหรือกลุ่มเอกสาร (corpus)

  • สร้างคลังคำศัพท์และวัดความถี่ของแต่ละคำ

Sentiment Analysis ด้วย Python

รีวิวสินค้า Amazon

10 แถวแรกของชุดข้อมูลรีวิวสินค้า Amazon

Sentiment Analysis ด้วย Python

การวิเคราะห์ความรู้สึกด้วย BOW: ตัวอย่าง

This is the best book ever. I loved the book and highly recommend it!!!

{'This': 1, 'is': 1, 'the': 2 , 'best': 1 , 'book': 2, 
'ever': 1, 'I':1 , 'loved':1 , 'and': 1  , 'highly': 1,
'recommend': 1 , 'it': 1 }
  • ลำดับคำและกฎไวยากรณ์จะหายไป!
Sentiment Analysis ด้วย Python

ผลลัพธ์สุดท้ายของ BOW

  • ผลลัพธ์จะมีลักษณะประมาณนี้:

5 แถวแรกของชุดข้อมูล แสดงผลลัพธ์ของวิธี BOW

Sentiment Analysis ด้วย Python

ฟังก์ชัน CountVectorizer

import pandas as pd
from sklearn.feature_extraction.text import CountVectorizer
vect = CountVectorizer(max_features=1000) 
vect.fit(data.review)
X = vect.transform(data.review)
Sentiment Analysis ด้วย Python

ผลลัพธ์ของ CountVectorizer

X
<10000x1000 sparse matrix of type '<class 'numpy.int64'>' 
  with 406668 stored elements in Compressed Sparse Row format>

Sentiment Analysis ด้วย Python

การแปลง vectorizer

# Transform to an array
my_array = X.toarray()
# Transform back to a DataFrame, assign column names
X_df = pd.DataFrame(my_array, columns=vect.get_feature_names())
Sentiment Analysis ด้วย Python

มาฝึกกันเถอะ!

Sentiment Analysis ด้วย Python

Preparing Video For Download...