電影評論的情緒分析
在這個練習中,你將以羅吉斯回歸對 Large Movie Review Dataset 的一小部分輸出機率進行探索。
變數 X 和 y 已載入環境中。X 含有依據電影評論中文字出現次數所建立的特徵,y 則是標籤,表示該評論的情緒是正向(+1)或負向(-1)。
本練習屬於課程
Python 中的線性分類器
練習說明
- 在電影評論資料上訓練一個羅吉斯回歸模型。
- 對給定的兩則評論,預測負向與正向的機率。
- 也可以自己寫一段評論,然後查看它的機率!
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# 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])