LoslegenKostenlos loslegen

Histograms for outlier detection

A histogram can be a compelling visual for finding outliers. They can become apparent when an appropriate number of bins is chosen for the histogram. Recall that the square root of the number of observations can be used as a rule of thumb for setting the number of bins. Usually, the bins with the lowest heights will contain outliers.

In this exercise, you'll plot the histogram of prices from the previous exercise. numpy and matplotlib.pyplot are available under their standard aliases.

Diese Übung ist Teil des Kurses

Anomaly Detection in Python

Kurs anzeigen

Anleitung zur Übung

  • Find the square root of the length of prices and store it as n_bins.
  • Cast n_bins to an integer.
  • Create a histogram of prices, setting the number of bins to n_bins.

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

# Find the square root of the length of prices
n_bins = ____

# Cast to an integer
n_bins = ____(____)

plt.figure(figsize=(8, 4))

# Create a histogram
plt.____(____, ____=____, color='red')
plt.show()
Code bearbeiten und ausführen