CommencerCommencer gratuitement

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.

Cet exercice fait partie du cours

Predicting CTR with Machine Learning in Python

Afficher le cours

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 and num_wrong respectively.
  • Compute accuracy using num_right and num_wrong using sum().

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de 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)
Modifier et exécuter le code