開始使用免費開始

具差分隱私的長條圖

在這個練習中,你會用具差分隱私的方法來存取 Heart Failure Prediction 資料集。你將產生並分析「非私密」與「私密」的長條圖,並加以比較。

你會聚焦在資料集的 age 變數所產生的長條圖。雖然你可以在主控台看到完整的 DataFrame,但在真實情境下,若不先依照差分隱私的全域方法加入隨機雜訊,你不會直接分享它。

DataFrame 已載入為 heart_df,而來自 age 的值已存成 ages 這個 Seriesdiffprivlib 中的 tools 也已經匯入。

本練習屬於課程

Data Privacy and Anonymization in Python

檢視課程

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# 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()
編輯並執行程式碼