解释机器学习模型的反事实——python工具箱
ceml的Python项目详细描述
ceml是一个用于计算反事实的python工具箱。反事实可以用来解释机器学习模型的预测。
它支持许多常见的机器学习框架:
- scikit-learn
- PyTorch
- Keras
- Tensorflow
此外,ceml易于使用,并且可以很容易地扩展。有关如何使用和扩展CEML的详细信息,请参阅以下用户指南。
安装
注意:需要python 3.6或更高版本!
Pypi
pip install ceml
注意:托管在pypi上的包仅使用cpu。如果要使用GPU,必须手动安装CEML—请参阅下一节。
吉特
下载或克隆存储库:
git clone https://github.com/andreArtelt/ceml.git
cd ceml
安装所有要求(在requirements.txt中列出):
pip install -r requirements.txt
注意:如果要使用gpu/tpu,必须手动安装jax、tensorflow和pytorch的gpu版本。不要使用pip install -r requirements.txt。
安装工具箱本身:
pip install
快速示例
#!/usr/bin/env python3# -*- coding: utf-8 -*-fromsklearn.datasetsimportload_irisfromsklearn.model_selectionimporttrain_test_splitfromsklearn.metricsimportaccuracy_scorefromsklearn.treeimportDecisionTreeClassifierfromceml.sklearnimportgenerate_counterfactualif__name__=="__main__":# Load dataX,y=load_iris(True)X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.33,random_state=4242)# Whitelist of features - list of features we can change/use when computing a counterfactualfeatures_whitelist=None# We can use all features# Create and fit modelmodel=DecisionTreeClassifier(max_depth=3)model.fit(X_train,y_train)# Select data point for explaining its predictionx=X_test[1,:]print("Prediction on x: {0}".format(model.predict([x])))# Compute counterfactualprint("\nCompute counterfactual ....")print(generate_counterfactual(model,x,y_target=0,features_whitelist=features_whitelist))
文档
文档可在readthedocs上获得:https://ceml.readthedocs.io/en/latest/
许可证
麻省理工学院许可证-请参见LICENSE.md
如何引用?
You can cite ceml by using the following BibTeX entry:
@misc{ceml, author = {André Artelt}, title = {CEML: Counterfactuals for Explaining Machine Learning models - A Python toolbox}, year = {2019}, publisher = {GitHub}, journal = {GitHub repository}, howpublished = {\url{https://www.github.com/andreArtelt/ceml}} }