Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

SKLearn Pipeline calculate sensitivity of categorical features for Local DP

未关闭
#389 2 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

@grilhami 已经在做这个了。

开始于 2021年11月30日。

评估

这个 Issue 还没有评估数据。

描述

Type: New Feature :heavy_plus_sign:

Feature Description

The current SKLearn Pipeline noise mechanism "operator" for Local DPassumes that the dataset given contains only all numerical features. This means that noise is calculated on top of the sensitivity calculation on numerical features.

However, most often, datasets also contain categorical features, which requires a different method to calculate the sensitivity. The "operator" should also support categorical features.

This applies to all the noise mechanisms: LaplaceMechanism, GaussianMechanism, and GeometricMechanism.

Note: as far as this issue was created, only LaplaceMechanism has been implemented, so it's a good starting point to start with LaplaceMechanism. Once GeometricMechanism and GaussianMechanism have been implemented, the specifications for categorical feature support are the same.

Additional Context

Preferably, the support for the categorial features would be in the form of parameters for the "operator" class.

For example, in the case of LaplaceMechanism, it would look something like this:

# Set a privacy budget accountant
accountant = BudgetAccountant(10000)

# Set sensitivity function for numerical data
sensitivity = lambda x: (max(x) - min(x))/ (len(x) + 1)

# Set sensitivity function for categorical data
sensitivity_cat = lambda x: ...

# Indecies of the categorical features in the dataset
cat_features = [0, 1, ...]

# Set laplace mechanism with epsilon, sensitivity, and accountant
laplace = LaplaceMechanism(
    epsilon=0.1, 
    sensitivity=sensitivity, 
    accountant=accountant,
    sensitivity_cat=sensitivity_cat,
    cat_features=cat_features
)

# Initialize scaler and naive bayes extimator
scaler = StandardScaler()
nb = GaussianNB()

# Create the pipeline
pipe = Pipeline([('scaler', scaler), ('laplace', laplace), ('nb', nb)])

For more examples, please have look at the notebook example of Laplace Mechanism's implementation.

As starting guidance, please refer to the source code for LaplaceMechanism in here.

主要语言
Python
星标
550
派生
142
PR 合并指标
30 天内没有已合并 PR

环境准备

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

OpenMined/PyDP 的其他 Issue

查看 OpenMined/PyDP 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。