MulaiMulai sekarang secara gratis

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.

Latihan ini adalah bagian dari kursus

Data Privacy and Anonymization in Python

Lihat Kursus

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# 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()
Edit dan Jalankan Kode