CommencerCommencer gratuitement

Logistic regression using Twitter data

In this exercise, you will build a logistic regression model using the tweets dataset. The target is given by the airline_sentiment, which is 0 for negative tweets, 1 for neutral, and 2 for positive ones. So, in this case, you are given a multi-class classification task. Everything we learned about binary problems applies to multi-class classification problems as well.

You will evaluate the accuracy of the model using the two different approaches from the slides.

The logistic regression function and accuracy score have been imported for you.

Cet exercice fait partie du cours

Sentiment Analysis in Python

Afficher le cours

Instructions

  • Build and fit a logistic regression model using the defined X and y as arguments.
  • Calculate the accuracy of the logistic regression model.
  • Predict the labels.
  • Calculate the accuracy score using the predicted and true labels.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# 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: ', ____(___, ____))
Modifier et exécuter le code