Skip to content

Commit

Permalink
Refactor project structure (#19)
Browse files Browse the repository at this point in the history
* format core.py

* update README.rst

* update setup.py

* Revert "update setup.py"

This reverts commit 1b49acc.

* update setup.py and README.rst

* Refactor project structure
  • Loading branch information
kyosek committed Jul 27, 2023
1 parent 6c77145 commit b83291e
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 40 deletions.
32 changes: 16 additions & 16 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CFXplorer
==========================================================================
=========

**Deployment & Documentation & Stats & License**

Expand All @@ -15,23 +15,23 @@ CFXplorer
:target: https://pepy.tech/project/focus-cfe
:alt: Downloads

.. image:: https://codecov.io/gh/kyosek/focus/branch/master/graph/badge.svg?token=G5I7TJR0JQ
:target: https://codecov.io/gh/kyosek/focus
.. image:: https://codecov.io/gh/kyosek/CFXplorer/branch/master/graph/badge.svg?token=G5I7TJR0JQ
:target: https://codecov.io/gh/kyosek/CFXplorer

.. image:: https://dl.circleci.com/status-badge/img/gh/kyosek/focus/tree/master.svg?style=svg
:target: https://dl.circleci.com/status-badge/redirect/gh/kyosek/focus/tree/master
.. image:: https://dl.circleci.com/status-badge/img/gh/kyosek/CFXplorer/tree/master.svg?style=svg
:target: https://dl.circleci.com/status-badge/redirect/gh/kyosek/CFXplorer/tree/master
:alt: Circle CI

.. image:: https://api.codeclimate.com/v1/badges/93840d29606abb212051/maintainability
:target: https://codeclimate.com/github/kyosek/focus-cfe/maintainability
:alt: Maintainability

.. image:: https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit
:target: https://github.com/kyosek/focus-cfe
:target: https://github.com/kyosek/CFXplorer
:alt: pre-commit

.. image:: https://img.shields.io/github/license/kyosek/focus.svg
:target: https://github.com/kyosek/focus/blob/master/LICENSE
.. image:: https://img.shields.io/github/license/kyosek/CFXplorer.svg
:target: https://github.com/kyosek/CFXplorer/blob/master/LICENSE
:alt: License

---------
Expand All @@ -53,7 +53,7 @@ It is recommended to use **pip** or **conda** for installation. Please make sure
.. code-block:: bash
conda install -c conda-forge focus-cfe
conda install -c conda-forge CFXplorer
Requirements
------------
Expand All @@ -80,9 +80,9 @@ Usage
Examples
--------

- Comprehensive examples can be found in the `examples folder <https://github.com/kyosek/focus/blob/master/examples/focus_example.py>`_.
- Kaggle notebook example can be found `here <https://www.kaggle.com/code/kyosukemorita/focus-cfe-example>`_.
- Below is demonstrated a comparison of before and after Focus-cfe is applied to feature set from the example given above.
- Comprehensive examples can be found in the `examples folder <https://github.com/kyosek/CFXplorer/blob/master/examples/focus_example.py>`_.
- Kaggle notebook example can be found `here <https://www.kaggle.com/code/kyosukemorita/focus-example>`__.
- Below is demonstrated a comparison of before and after Focus is applied to feature set from the example given above.

.. image:: https://raw.githubusercontent.com/kyosek/focus/master/docs/plot.png
:width: 800px
Expand All @@ -100,16 +100,16 @@ Limitations of Focus class
Documentation
-------------

The documentation can be found `here <https://cfxplorer.readthedocs.io/en/latest/>`_.
The documentation can be found `here <https://cfxplorer.readthedocs.io/en/latest/>`__.

Contributing
------------

If you would like to contribute to the project, please refer to;

- `ISSUE_TEMPLATE <https://github.com/kyosek/focus/tree/master/.github/ISSUE_TEMPLATE>`_ for raising an issue
- `PULL_REQUEST_TEMPLATE.md <https://github.com/kyosek/focus/blob/master/.github/PULL_REQUEST_TEMPLATE.md>`_ for raising a PR
- `ISSUE_TEMPLATE <https://github.com/kyosek/CFXplorer/tree/master/.github/ISSUE_TEMPLATE>`_ for raising an issue
- `PULL_REQUEST_TEMPLATE.md <https://github.com/kyosek/CFXplorer/blob/master/.github/PULL_REQUEST_TEMPLATE.md>`_ for raising a PR

License
-------
This package is using the `Apache License 2.0 <https://github.com/kyosek/focus/blob/master/LICENSE>`_ license.
This package is using the `Apache License 2.0 <https://github.com/kyosek/CFXplorer/blob/master/LICENSE>`_ license.
2 changes: 1 addition & 1 deletion cfxplorer/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from cfxplorer.focus.core import Focus
from cfxplorer.focus import Focus

# Let users know if they're missing any of our hard dependencies
_hard_dependencies = ("tensorflow", "numpy")
Expand Down
22 changes: 11 additions & 11 deletions cfxplorer/focus/core.py → cfxplorer/focus.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from sklearn.ensemble import AdaBoostClassifier, RandomForestClassifier
from sklearn.tree import DecisionTreeClassifier

from .utils import calculate_distance
from cfxplorer.utils import calculate_distance

os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"

Expand Down Expand Up @@ -67,12 +67,12 @@ class Focus:
Examples
--------
- Initialize FOCUS with default parameters
- Initialize FOCUS on default parameters
- Generate counterfactual explanations
cfxplorer = Focus()
focus = Focus()
cfe_features = cfxplorer.generate(model, X)
cfe_features = focus.generate(model, X)
"""

def __init__(
Expand Down Expand Up @@ -475,16 +475,16 @@ def filter_hinge_loss(
Calculates the filtered probabilities of each data point for the given model.
Args:
- n_class (int): Number of classes.
- mask_vector (np.ndarray): A boolean mask indicating which data points should be considered.
- X (tf.Tensor): The feature input for the model.
- sigma (float): The value of sigma for computing the probabilities.
- temperature (float): The temperature to be used for the softmax function.
- model: The machine learning model;
n_class (int): Number of classes.
mask_vector (np.ndarray): A boolean mask indicating which data points should be considered.
X (tf.Tensor): The feature input for the model.
sigma (float): The value of sigma for computing the probabilities.
temperature (float): The temperature to be used for the softmax function.
model: The machine learning model;
e.g., DecisionTreeClassifier, RandomForestClassifier, AdaBoostClassifier.
Returns:
- hinge_loss (tf.Tensor): The filtered probabilities of each data point.
hinge_loss (tf.Tensor): The filtered probabilities of each data point.
"""
n_input = X.shape[0]

Expand Down
2 changes: 1 addition & 1 deletion cfxplorer/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest
import tensorflow as tf

from cfxplorer.focus.utils import (
from cfxplorer.utils import (
calculate_distance,
safe_cosine,
safe_euclidean,
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions cfxplorer/version.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
``cfxplorer`` is a python package for
generating counterfactual explanations for a tree-based model
``CFXplorer`` is a python package for
generating counterfactual explanations for a given model and feature set.
"""
# PEP0440 compatible formatted version, see:
# https://www.python.org/dev/peps/pep-0440/
Expand All @@ -18,4 +18,4 @@
# Dev branch marker is: 'X.Y.dev' or 'X.Y.devN' where N is an integer.
# 'X.Y.dev0' is the canonical version of 'X.Y.dev'
#
__version__ = "0.0.dev4" # pragma: no cover
__version__ = "0.0.dev7" # pragma: no cover
9 changes: 1 addition & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@

from setuptools import find_packages, setup

DESCRIPTION = (
"CFXplorer is a python package for " "generating counterfactual explanations"
)

DESCRIPTION = "CFXplorer is a python package for generating counterfactual explanations for given model and feature set"

# get __version__ from _version.py
ver_file = path.join("cfxplorer", "version.py")
Expand All @@ -22,10 +19,6 @@ def readme():
return f.read()


# read the contents of requirements.txt
with open(path.join(this_directory, "requirements.txt"), encoding="utf-8") as f:
requirements = f.read().splitlines()

setup(
name="CFXplorer",
version=__version__,
Expand Down

0 comments on commit b83291e

Please sign in to comment.