LoslegenKostenlos loslegen

Histograms with differential privacy

In this exercise, you'll access the Heart Failure Prediction dataset following the differentially private approach. You will generate and analyze private and non-private histograms and compare them.

You'll focus on histograms from the age variable of the dataset. Although you can access the intact DataFrame in the console, in real life, you wouldn't share it without adding random noise calculated by differential privacy, following the global approach.

The DataFrame is loaded as heart_df while the Series holding the values from age is stored as ages. tools from diffprivlib is already imported.

Diese Übung ist Teil des Kurses

Data Privacy and Anonymization in Python

Kurs anzeigen

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# Get counts and bars for non-private histogram of ages
counts, bins = ____

# Normalize counts to get proportions
proportions = ____

# Draw the histogram of proportions
plt.bar(____[: - 1], height=____, width=(bins[1] - bins[0]))
plt.show()
Code bearbeiten und ausführen