Logistic Regression โดยใช้ข้อมูล Twitter
ในแบบฝึกหัดนี้ จะได้สร้างโมเดล logistic regression โดยใช้ชุดข้อมูล tweets โดยตัวแปรเป้าหมายคือ airline_sentiment ซึ่ง 0 หมายถึงทวีตเชิงลบ 1 หมายถึงทวีตกลาง ๆ และ 2 หมายถึงทวีตเชิงบวก นั่นคือในกรณีนี้เป็นงาน classification แบบหลายคลาส (multi-class) ซึ่งหลักการที่เรียนมาสำหรับปัญหาแบบ binary นั้นใช้ได้กับ multi-class classification เช่นกัน
จากนั้นจะประเมินความแม่นยำของโมเดลด้วยสองวิธีที่แนะนำในสไลด์
ฟังก์ชัน logistic regression และ accuracy score ได้ถูก import ไว้ให้แล้ว
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Sentiment Analysis ด้วย Python
คำแนะนำการฝึกหัด
- สร้างและ fit โมเดล logistic regression โดยใช้
Xและyที่กำหนดไว้เป็นอาร์กิวเมนต์ - คำนวณความแม่นยำของโมเดล logistic regression
- ทำนาย label
- คำนวณ accuracy score โดยใช้ label ที่ทำนายได้และ label จริง
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Define the vector of targets and matrix of features
y = tweets.airline_sentiment
X = tweets.drop('airline_sentiment', axis=1)
# Build a logistic regression model and calculate the accuracy
log_reg = ____.____(X, y)
print('Accuracy of logistic regression: ', log_reg.____)
# Create an array of prediction
y_predict = log_reg.____
# Print the accuracy using accuracy score
print('Accuracy of logistic regression: ', ____(___, ____))