LoslegenKostenlos loslegen

Data masking with PCA

PCA for pseudo-anonymization is widely used among companies. You can find multiple Kaggle challenges and datasets where the data is provided after PCA transformations.

A differentially private version of PCA is also included in the diffprivlib in the models module. It's based on the PCA class from sklearn but including optional arguments for epsilon and min and max bounds. Just as we have seen in the previous chapter.

In this exercise, you will apply data masking with PCA on the NBA Salaries dataset, already loaded as players.

Diese Übung ist Teil des Kurses

Data Privacy and Anonymization in Python

Kurs anzeigen

Anleitung zur Übung

  • Import PCA from sklearn.
  • Initialize PCA() with the number of components to be the same as the number of columns.
  • Apply pca to players.
  • See the resulting dataset.

Interaktive Übung

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

# Import PCA from Scikit-learn
____

# Initialize PCA with number of components to be the same as the number of columns
pca = ____

# Apply PCA to the data
players_pca = ____

# Print the resulting dataset
print(pd.DataFrame(players_pca))
Code bearbeiten und ausführen