Logistic regression of movie reviews
In the video we learned that logistic regression is a common way to model a classification task, such as classifying the sentiment as positive or negative.
In this exercise, you will work with the movies reviews dataset. The label column stores the sentiment, which is 1 when the review is positive, and 0 when negative. The text review has been transformed, using BOW, to numeric columns.
Your task is to build a logistic regression model using the movies dataset and calculate its accuracy.
Bài tập này là một phần của khóa học
Sentiment Analysis in Python
Hướng dẫn bài tập
- Import the logistic regression function.
- Create and fit a logistic regression on the labels
yand the featuresX. - Calculate the accuracy of the logistic regression model, using the default
.score()method.
Bài tập tương tác thực hành trực tiếp
Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.
# 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))