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.
Deze oefening maakt deel uit van de cursus
Sentiment Analysis in Python
Oefeninstructies
- Build and fit a logistic regression model using the defined
Xandyas arguments. - Calculate the accuracy of the logistic regression model.
- Predict the labels.
- Calculate the accuracy score using the predicted and true labels.
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
# 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: ', ____(___, ____))