Python文档生成器

py-ciu的Python项目详细描述


CircleCI

py ciu公司

可解释机器学习通过上下文重要性和效用

py ciu库提供了为 基于机器学习的分类器。 它是模型不可知论的,并回答了以下问题,给出了一个分类 决定:

  • 如何将important作为 分类决策?(上下文重要性,CI)

  • 如何将typical作为 给定的班级?(上下文实用程序,CU)

使用

安装py ciu

pip install py-ciu

导入库:

^{pr2}$

为了这个例子,让我们还导入一个数据生成器,创建一个 合成数据集,并训练模型:

fromsklearn.ensembleimportRandomForestClassifierfromciu_tests.loan_data_generatorimportgenerate_datadata=generate_data()train_data=data['train'][1]test_data=datatest_data_encoded=data['test'][1].drop(['approved'],axis=1)random_forest=RandomForestClassifier(n_estimators=1000,random_state=42)labels=train_data[['approved']].values.ravel()data=train_data.drop(['approved'],axis=1)random_forest.fit(data,labels)

然后对需要解释的案例进行分类,确定预测指标 对于我们感兴趣的课程:

feature_names=['age','assets','monthly_income','gender_female','gender_male','gender_other','job_type_fixed','job_type_none','job_type_permanent']case=test_data_encoded.values[0]example_prediction=random_forest.predict([test_data_encoded.values[0]])example_prediction_prob=random_forest.predict_proba([test_data_encoded.values[0]])prediction_index=0ifexample_prediction[0]>0.5else1print(feature_names)print(f'Case: {case}; Prediction {example_prediction}; Probability: {example_prediction_prob}')

现在,我们可以调用py ciudetermine_ciu函数。 函数采用以下参数:

  • case_data:包含案例数据的字典。在

  • predictor:黑盒模型py ciu的预测函数应该 打电话。在

  • min_maxs:包含功能名称(键)和 最小值、最大值,加上一个值,该值指示 必须是整数('feature_name': [min, max, is_int])。在

  • samples(可选):将生成py ciu的样本数。默认值 到1000。在

  • prediction_index(可选):如果模型返回几个 预测,有可能提供 相关预测指标。默认为 None。在

  • category_mapping(可选):一个热编码类别的映射 类别和类别列表的变量 名字。{cd9>默认为^。在

  • feature_interactions(可选):一个{key: list}元组的列表 其交互作用应该是 评价的。默认为[]。在

我们配置CIU参数并调用CIU函数:

category_mapping={'gender':['gender_female','gender_male','gender_other'],'job_type':['job_type_fixed','job_type_none','job_type_permanent']}feature_interactions=[{'assets_income':['assets','monthly_income']}]ciu=determine_ciu(test_data_encoded.iloc[0,:].to_dict(),random_forest.predict_proba,{'age':[20,70,True],'assets':[-20000,150000,True],'monthly_income':[0,20000,True],'gender_female':[0,1,True],'gender_male':[0,1,True],'gender_other':[0,1,True],'job_type_fixed':[0,1,True],'job_type_none':[0,1,True],'job_type_permanent':[0,1,True]},1000,prediction_index,category_mapping,feature_interactions)

函数返回一个ciu对象,我们从中检索CIU度量:

print(ciu.ci,ciu.cu)

我们还可以自动生成CIU图:

ciu.plot_ci()ciu.plot_cu()

此外,我们可以根据CIU生成文本解释:

print(ciu.text_explain())

看看 examples目录到 了解更多。在

作者

许可证

库在BSD Clause-2 License下发布。在

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

推荐PyPI第三方库


热门话题
在Eclipse中使用多个调用在一行上打印java   javajackson序列化问题。只有同一实体的第一个对象可以很好地序列化   Java中Deflate函数的等价充气   使用customlitview的java Android actionbar搜索   java“<T>T get()”是什么意思?(它有用吗?)   目标c使用CommonCrypto使用AES256加密,使用OpenSSL或Java解密   java在运行时更新资源文件   fileinputstream在java中访问并将数据写入现有文件   带集群的java Android Mapbox我希望每个功能都有不同的标记图像   java JDK8>JDK10:PKIX路径生成失败:SunCertPathBuilderException:找不到请求目标的有效证书路径   java使用Hk2生成具有指定构造函数参数的实例   为什么这个系统。出来Java中的println()打印到控制台?   java目录和文件名连接不起作用   使用mockito和通配符绘图的java