電影評論的邏輯斯迴歸
在影片中我們學到,邏輯斯迴歸是建構分類任務的常見方法,例如將情緒分類為正向或負向。
在這個練習中,你會使用 movies 評論資料集。label 欄位儲存情緒標籤,評論為正向時為 1,負向時為 0。文字評論已使用 BOW 轉換為數值欄位。
你的任務是使用 movies 資料集建立一個邏輯斯迴歸模型,並計算其準確率。
本練習屬於課程
Python 情感分析
練習說明
- 匯入邏輯斯迴歸函式。
- 建立並以標籤
y與特徵X來擬合一個邏輯斯迴歸模型。 - 使用預設的
.score()方法計算邏輯斯迴歸模型的準確率。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import the logistic regression
from ____.____ import ____
# Define the vector of targets and matrix of features
y = movies.label
X = movies.drop('label', axis=1)
# Build a logistic regression model and calculate the accuracy
log_reg = ____.____(X, y)
print('Accuracy of logistic regression: ', log_reg.____(X, y))