黑箱模型特征相关性度量模块

fairml的Python项目详细描述


fairml是一个python工具箱,用于审核 偏见。

Build StatusCoverage StatusGitHub licenseGitHub issues

Logo

徽标

说明

越来越多的预测模型被用于 确定获得信贷、保险和 就业。尽管社会在效率和生产力方面取得了进步 通过部署这些模型,潜在的系统缺陷并没有 已得到充分解决,特别是无意中 歧视。这种歧视可能是基于种族, 性别、宗教、性取向或其他特征。这个 project解决了这个问题:分析师如何确定 年黑箱预测模型输入的相对重要性 为了评估模型的公平性(或歧视程度)?

我们提出了一个用于审计预测模型的端到端工具箱fairml 通过量化模型输入的相对重要性。费尔姆 利用模型压缩和四种输入排序算法 量化模型对其输入的相对预测依赖性。这个 输入对预测模型的相对重要性可以是 用于评估此类模型的公平性(或歧视程度)。 使用fairml,分析师可以更容易地审计繁琐的预测模型 很难解释黑箱算法和 相应的输入数据。

安装

您可以通过github安装这个包,也就是说,这个repo使用 以下命令:

pip安装https://github.com/adebayoj/fairml/archive/master.zip

或者您可以克隆存储库执行以下操作:

git克隆https://github.com/adebayoj/fairml.git

sudo python setup.py安装

方法论

Methodology

方法论

代码演示

现在我们展示如何使用fairml python包审计黑盒 模型。

# First we import modules for model building and data processing.importpandasaspdimportnumpyasnpfromsklearn.linear_modelimportLogisticRegression"""
Now, we import the two key methods from fairml.
audit_model takes:

- (required) black-box function, which is the model to be audited
- (required) sample_data to be perturbed for querying the function. This has to be a pandas dataframe with no missing data.

- other optional parameters that control the mechanics of the auditing process, for example:
  - number_of_runs : number of iterations to perform
  - interactions : flag to enable checking model dependence on interactions.

audit_model returns an overloaded dictionary where keys are the column names of input pandas dataframe and values are
    lists containing model  dependence on that particular feature. These lists of size number_of_runs.

"""fromfairmlimportaudit_modelfromfairmlimportplot_generic_dependence_dictionary

上面,我们提供了对fairml关键功能的快速解释。 现在我们开始构建一个我们想要审计的示例模型。

# read in the propublica data to be used for our analysis.propublica_data=pd.read_csv(filepath_or_buffer="./doc/example_notebooks/""propublica_data_for_fairml.csv")# create feature and design matrix for model building.compas_rating=propublica_data.score_factor.valuespropublica_data=propublica_data.drop("score_factor",1)# this is just for demonstration, any classifier or regressor# can be used here. fairml only requires a predict function# to diagnose a black-box model.# we fit a quick and dirty logistic regression sklearn# model here.clf=LogisticRegression(penalty='l2',C=0.01)clf.fit(propublica_data.values,compas_rating)

现在让我们审核用fairml构建的模型。

#  call audit model with modeltotal,_=audit_model(clf.predict,propublica_data)# print feature importanceprint(total)# generate feature dependence plotfig=plot_dependencies(total.get_compress_dictionary_into_key_median(),reverse_values=False,title="FairML feature dependence")plt.savefig("fairml_ldp.eps",transparent=False,bbox_inches='tight')

上面的演示生成下图。

Example Output

示例输出

如有任何问题,请随时向作者发送电子邮件:

数据

用于上述演示的数据可在回购协议中获得,网址为: /doc/example_笔记本/propublica_data_for_fairml.csv

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java为什么程序显示空结果?   java应用程序在测试设备上调试时工作正常,但在发布版apk中没有,它没有获得post。来自firebase的类变量   java Android:从主活动按钮确定在listview中选中哪个复选框   在Spring中添加@OneToOne注释时启动ApplicationContext时发生java错误   用JAVA Android实现矩阵计算的最快方法   SpringJava语义有没有更好的编写方法?   java从hashmap中减去两个值后返回最小差值的键?   Java中的静态初始化顺序:Netty 4.0.7的例外   java如何检查用户输入是否为字符串   循环Java计数单词索引   java如何使用以下代码将视频流传输到Android异步Http服务器?   java如何在jtable的所有行中循环   java如何使用maven将unicode插入mysql   java使用安卓加速远程数据检索   java试图模拟麦克风(javax.sound.sampled)   swing SwingWorker从不归还任何东西?(爪哇)   首次在Android Studio上未加载java LibGDX文件   java如何在多个Mysql服务器上设置限制和偏移?   如何防止从java连接到mongodb时登录控制台?