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.
Este ejercicio forma parte del curso
Sentiment Analysis in Python
Instrucciones del ejercicio
- Import the logistic regression function.
- Create and fit a logistic regression on the labels
y
and the featuresX
. - Calculate the accuracy of the logistic regression model, using the default
.score()
method.
Ejercicio interactivo práctico
Prueba este ejercicio completando el código de muestra.
# 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))