มาทำนายความรู้สึกกันเถอะ!

Sentiment Analysis ด้วย Python

Violeta Misheva

Data Scientist

ปัญหาการจำแนกประเภท

  • รีวิวสินค้าและภาพยนตร์: ความรู้สึกเชิงบวกหรือเชิงลบ (การจำแนกแบบไบนารี)
  • ทวีตเกี่ยวกับสายการบิน: เชิงบวก เป็นกลาง และเชิงลบ (การจำแนกแบบหลายคลาส)
Sentiment Analysis ด้วย Python

Linear regression และ Logistic regression

กราฟแสดง linear regression (ซ้าย) ที่ฟิตกับข้อมูลบางส่วน และ logistic regression (ขวา) ที่ฟิตกับข้อมูลในลักษณะเดียวกัน

Sentiment Analysis ด้วย Python

ฟังก์ชัน Logistic

  • Linear regression: ผลลัพธ์เป็นตัวเลข
  • Logistic regression: ความน่าจะเป็น:

$$ Probability(sentiment=positive|review) $$

กราฟแสดงฟังก์ชัน logistic (sigmoid) ที่ฟิตกับข้อมูลตัวอย่างบางส่วน

Sentiment Analysis ด้วย Python

Logistic regression ใน Python

from sklearn.linear_model import LogisticRegression
log_reg = LogisticRegression().fit(X, y)
Sentiment Analysis ด้วย Python

วัดประสิทธิภาพของโมเดล

Accuracy: สัดส่วนของการพยากรณ์ที่โมเดลทำได้ถูกต้อง

  • ค่า accuracy ยิ่งสูงและใกล้ 1 มากเท่าไร ยิ่งดีเท่านั้น
# Accuracy using score
score = log_reg.score(X, y)
print(score)
0.9009
Sentiment Analysis ด้วย Python

การใช้ accuracy score

# Accuracy using accuracy_score
from sklearn.metrics import accuracy_score
y_predicted = log_reg.predict(X)
acurracy = accuracy_score(y, y_predicted)
0.9009
Sentiment Analysis ด้วย Python

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

Sentiment Analysis ด้วย Python

Preparing Video For Download...