การวิเคราะห์ความรู้สึกจากรีวิวภาพยนตร์
ในแบบฝึกหัดนี้ เราจะสำรวจค่าความน่าจะเป็นที่ได้จาก logistic regression บนชุดข้อมูลย่อยจาก Large Movie Review Dataset
ตัวแปร X และ y ถูกโหลดไว้ในสภาพแวดล้อมแล้ว โดย X ประกอบด้วยฟีเจอร์ที่อิงจากความถี่ของคำในรีวิวภาพยนตร์ และ y ประกอบด้วย label ที่บอกว่ารีวิวนั้นมีความรู้สึกเชิงบวก (+1) หรือเชิงลบ (-1)
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Linear Classifiers ใน Python
คำแนะนำการฝึกหัด
- เทรนโมเดล logistic regression บนข้อมูลรีวิวภาพยนตร์
- ทำนายความน่าจะเป็นของรีวิวเชิงลบและเชิงบวกสำหรับรีวิวสองรายการที่กำหนดให้
- ลองเขียนรีวิวของตัวเองและดูค่าความน่าจะเป็นที่ได้ได้เลย!
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Instantiate logistic regression and train
lr = ____
lr.fit(____)
# Predict sentiment for a glowing review
review1 = "LOVED IT! This movie was amazing. Top 10 this year."
review1_features = get_features(review1)
print("Review:", review1)
print("Probability of positive review:", lr.predict_proba(____)[0,1])
# Predict sentiment for a poor review
review2 = "Total junk! I'll never watch a film by that director again, no matter how good the reviews."
review2_features = get_features(review2)
print("Review:", review2)
print("Probability of positive review:", lr.predict_proba(____)[0,1])