IniziaInizia gratis

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.

Questo esercizio fa parte del corso

Sentiment Analysis in Python

Visualizza il corso

Istruzioni dell'esercizio

  • 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.

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

# 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: ', ____(___, ____))
Modifica ed esegui il codice