Skip to content

Commit

Permalink
pyexplainer version 0.1.9 with AutoSpearman
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelFu1998-create committed Apr 14, 2021
1 parent 6ad9406 commit f728c5d
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/pyExplainer.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added dist/pyexplainer-0.1.9-py3-none-any.whl
Binary file not shown.
Binary file added dist/pyexplainer-0.1.9.tar.gz
Binary file not shown.
60 changes: 59 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyexplainer/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.1.8'
__version__ = '0.1.9'
Binary file modified pyexplainer/__pycache__/pyexplainer_pyexplainer.cpython-38.pyc
Binary file not shown.
20 changes: 13 additions & 7 deletions pyexplainer/pyexplainer_pyexplainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,23 +228,20 @@ def __init__(self,
self.X_explain = None
self.y_explain = None

def auto_spearman(self, correlation_threshold=0.7, correlation_method='spearman', VIF_threshold=5):
def auto_spearman(self, apply_to_X_train=True, correlation_threshold=0.7, correlation_method='spearman', VIF_threshold=5):
"""An automated feature selection approach that address collinearity and multicollinearity.
For more information, please kindly refer to the `paper <https://ieeexplore.ieee.org/document/8530020>`_.
Parameters
----------
apply_to_X_train : :obj:`bool`
Whether to apply the selected columns to the X_train data inside PyExplainer Obj., default is True
correlation_threshold : :obj:`float`
Threshold value of correalation.
correlation_method : :obj:`str`
Method for solving the correlation between the features.
VIF_threshold : :obj:`int`
Threshold value of VIF score.
Returns
-------
:obj:`pandas.core.frame.DataFrame`
A Dataframe that contains selected features
"""
X_AS_train = self.X_train.copy()
AS_metrics = X_AS_train.columns
Expand Down Expand Up @@ -336,7 +333,9 @@ def auto_spearman(self, correlation_threshold=0.7, correlation_method='spearman'
X_AS_train = X_AS_train.loc[:, selected_features]

print('Finally, according to Part 2 of AutoSpearman,', AS_metrics, 'are selected.')
return AS_metrics
if apply_to_X_train:
self.set_X_train(X_AS_train)
print('X_train data inside PyExplainer was updated based on the selected features above')

def explain(self,
X_explain,
Expand Down Expand Up @@ -1291,6 +1290,13 @@ def set_top_k_rules(self, top_k_rules):
self.top_k_rules = top_k_rules

def set_X_train(self, X_train):
"""Setter of X_train
Parameters
----------
X_train : :obj:`pandas.core.frame.DataFrame`
X_train data
"""
if isinstance(X_train, pd.core.frame.DataFrame):
self.X_train = X_train
else:
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pyexplainer"
version = "0.1.8"
version = "0.1.9"
description = "Explainable AI tool for Software Quality Assurance (SQA)"
authors = ["Michael <michaelfu1998@gmail.com>"]
license = "MIT"
Expand All @@ -13,6 +13,7 @@ scipy = "^1.6.1"
ipywidgets = "^7.6.3"
ipython = "^7.21.0"
pandas = "^1.2.3"
statsmodels = "^0.12.2"

[tool.poetry.dev-dependencies]
Sphinx = "^3.5.1"
Expand Down
Binary file modified setup.py
Binary file not shown.
Binary file modified tests/__pycache__/test_pyexplainer.cpython-38-pytest-6.2.2.pyc
Binary file not shown.
7 changes: 6 additions & 1 deletion tests/test_pyexplainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def in_virtualenv():


def test_version():
assert __version__ == '0.1.8'
assert __version__ == '0.1.9'


@pytest.mark.parametrize('data, result',
Expand Down Expand Up @@ -205,6 +205,11 @@ def test_pyexplainer_init_positive(X_train, y_train, indep, dep, blackbox_model,
'dep', 'top_k_positive_rules', 'top_k_negative_rules', 'local_rulefit_model']


def test_auto_spearman():
py_explainer.auto_spearman()
py_explainer.auto_spearman(apply_to_X_train=False)


@pytest.mark.parametrize('exp_X_explain, exp_y_explain, top_k, max_rules, max_iter, cv, search_function, debug, '
'X_train, result',
[
Expand Down

0 comments on commit f728c5d

Please sign in to comment.