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.
Diese Übung ist Teil des Kurses
Sentiment Analysis in Python
Anleitung zur Übung
- 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.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# 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))