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.
Este ejercicio forma parte del curso
Sentiment Analysis in Python
Instrucciones del ejercicio
- Build and fit a logistic regression model using the defined
X
andy
as arguments. - Calculate the accuracy of the logistic regression model.
- Predict the labels.
- Calculate the accuracy score using the predicted and true labels.
Ejercicio interactivo práctico
Prueba este ejercicio completando el código de muestra.
# 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: ', ____(___, ____))