使用 Twitter 資料的羅吉斯回歸
在這個練習中,你將使用 tweets 資料集建立一個羅吉斯回歸模型。目標欄位是 airline_sentiment:負向推文為 0、中立為 1、正向為 2。也就是說,這是一個多類別分類任務。我們針對二元分類所學到的概念,同樣適用於多類別分類。
你會用投影片中的兩種方法來評估模型的正確率。
羅吉斯回歸函式與正確率評分工具已為你匯入。
本練習屬於課程
Python 情感分析
練習說明
- 使用定義好的
X和y作為引數,建立並訓練羅吉斯回歸模型。 - 計算羅吉斯回歸模型的正確率。
- 預測標籤。
- 使用預測與真實標籤計算「accuracy score」。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# 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: ', ____(___, ____))