Get startedGet started for free

Visualizing easy and difficult examples

In this exercise, you'll visualize the examples that the logistic regression model is most and least confident about by looking at the largest and smallest predicted probabilities.

The handwritten digits dataset is already loaded into the variables X and y. The show_digit function takes in an integer index and plots the corresponding image, with some extra information displayed above the image.

This exercise is part of the course

Linear Classifiers in Python

View Course

Exercise instructions

  • Fill in the first blank with the index of the digit that the model is most confident about.
  • Fill in the second blank with the index of the digit that the model is least confident about.
  • Observe the images: do you agree that the first one is less ambiguous than the second?

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

lr = LogisticRegression()
lr.fit(X,y)

# Get predicted probabilities
proba = lr.predict_proba(X)

# Sort the example indices by their maximum probability
proba_inds = np.argsort(np.max(proba,axis=1))

# Show the most confident (least ambiguous) digit
show_digit(____, lr)

# Show the least confident (most ambiguous) digit
show_digit(____, lr)
Edit and Run Code