MulaiMulai sekarang secara gratis

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.

Latihan ini adalah bagian dari kursus

Sentiment Analysis in Python

Lihat Kursus

Petunjuk latihan

  • Import the logistic regression function.
  • Create and fit a logistic regression on the labels y and the features X.
  • Calculate the accuracy of the logistic regression model, using the default .score() method.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# 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))
Edit dan Jalankan Kode