Fit logistic regression model
Logistic regression is a simple yet very powerful classification model that is used in many different use cases. You will now fit a logistic regression on the training part of the telecom churn dataset, and then predict labels on the unseen test set. Afterwards, you will calculate the accuracy of your model predictions.
The accuracy_score
function has been imported, and a LogisticRegression
instance from sklearn
has been initialized as logreg
. The training and testing datasets that you've built previously have been loaded as train_X
and test_X
for features, and train_Y
and test_Y
for target variables.
Cet exercice fait partie du cours
Machine Learning for Marketing in Python
Instructions
- Fit a logistic regression on the training data.
- Predict churn labels for the test data.
- Calculate the accuracy score on the testing data.
- Print the test accuracy rounded to 4 decimals.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
# Fit logistic regression on training data
logreg.___(train_X, train_Y)
# Predict churn labels on testing data
pred_test_Y = ___.predict(test_X)
# Calculate accuracy score on testing data
test_accuracy = ___(test_Y, pred_test_Y)
# Print test accuracy score rounded to 4 decimals
print('Test accuracy:', ___(test_accuracy, 4))