Logistic regression for images
In this exercise, you will build a logistic regression model on a breast cancer dataset from the last exercise and evaluate its accuracy.
The X_train
, X_test
, y_train
, and y_test
that you created in the last exercise are available in your workspace, along with sklearn
and pandas
as pd
. LogisticRegression
is available via sklearn.linear_model
.
This exercise is part of the course
Predicting CTR with Machine Learning in Python
Exercise instructions
- Create a logistic regression classifier.
- Fit the classifier using training data to make predictions for the testing data.
- Assign totals for correct and incorrect predictions between training and testing targets to
num_right
andnum_wrong
respectively. - Compute accuracy using
num_right
andnum_wrong
usingsum()
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create and fit a logistic regression classifier
clf = ____().____(X_train, y_train)
# Predict labels
y_pred = clf.____(X_test)
# Get number of right and wrong predictions
num_right = (y_test == y_pred).____()
num_wrong = (y_test != y_pred).____()
# Compute and print accuracy
accuracy = 1.0 * num_right / (____ + ____)
print(accuracy)