Skip to content

Commit

Permalink
add files
Browse files Browse the repository at this point in the history
  • Loading branch information
kyosek committed Jul 15, 2023
1 parent 9c49ec3 commit 405619c
Show file tree
Hide file tree
Showing 11 changed files with 271 additions and 39 deletions.
25 changes: 25 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
comment: false

coverage:
status:
project:
default:
# Commits pushed to main should not make the overall
# project coverage decrease by more than 1%:
target: auto
threshold: 1%
patch:
default:
# Be tolerant on slight code coverage diff on PRs to limit
# noisy red coverage status on github PRs.
# Note: The coverage stats are still uploaded
# to codecov so that PR reviewers can see uncovered lines
target: auto
threshold: 1%

codecov:
notify:
# Prevent coverage status to upload multiple times for parallel and long
# running CI pipelines. This configuration is particularly useful on PRs
# to avoid confusion.
after_n_builds: 6
5 changes: 5 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[settings]
line_length = 79
multi_line_output = 3
include_trailing_comma = True
skip = [".gitignore", ".rst", "examples."]
33 changes: 33 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/pycqa/isort
rev: 5.11.2
hooks:
- id: isort
name: isort
entry: isort
description: Order imports
language: system
types: [python]
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
name: flake8
entry: flake8
language: system
types: [python]
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
name: black
entry: black
description: Code reformatting
language: system
types: [python]
15 changes: 13 additions & 2 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,26 @@
# Required
version: 2

build:
os: "ubuntu-20.04"
tools:
python: "miniconda3-4.7"

# Build documentation in the docs/ directory with Sphinx
sphinx:
builder: html
configuration: docs/conf.py

# Optionally build your docs in additional formats such as PDF and ePub
formats: all
formats:
- pdf

# ReadTheDocs.io need to install the dependencies to be able
# to build the documentation automatically.
python:
install:
- requirements: requirements.txt
- requirements: requirements.txt

submodules:
include: all
recursive: true
37 changes: 37 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
language: python
os: linux
dist: xenial

env:
global:
PIP_PREFER_BINARY=true

python:
- "3.5"
- "3.6"
- "3.7"
- "3.8"
- "3.9"
- "3.10"
- "3.11"

install:
- pip install --upgrade pip
- pip install -r requirements_ci.txt
- pip install pytest
- pip install pytest-cov
- pip install coveralls

# command to run tests
script:
pytest --cov=pyod/

after_success:
- coveralls

notifications:
email:
recipients:
- [email protected]
on_success: never # default: change
on_failure: always # default: always
28 changes: 26 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,38 @@ FOCUS: Flexible Optimizable Counterfactual Explanations for Tree Ensembles
:target: https://pypi.org/project/focus-cfe/
:alt: PyPI version

.. image:: https://coveralls.io/repos/github/kyosek/focus-cfe/badge.svg
:target: https://coveralls.io/github/kyosek/focus-cfe
.. image:: https://readthedocs.org/projects/focus-cfe/badge/?version=latest
:target: https://focus-cfe.readthedocs.io/en/latest/?badge=latest
:alt: Documentation status

.. image:: https://img.shields.io/github/stars/kyosek/focus.svg
:target: https://github.com/kyosek/focus/stargazers
:alt: GitHub stars

.. image:: https://img.shields.io/github/forks/kyosek/focus.svg?color=blue
:target: https://github.com/kyosek/focus/network
:alt: GitHub forks

.. image:: https://pepy.tech/badge/focus-cfe
:target: https://pepy.tech/project/focus-cfe
:alt: Downloads

.. image:: https://coveralls.io/repos/github/kyosek/focus/badge.svg
:target: https://coveralls.io/github/kyosek/focus
:alt: Coverage Status

.. 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
:alt: pre-commit

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

-----

This library is an implementation of `FOCUS: Flexible Optimizable Counterfactual Explanations for Tree Ensembles <https://arxiv.org/abs/1911.12199>`_.
Expand Down
31 changes: 31 additions & 0 deletions circleci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
version: 2.1

orbs:
node: circleci/[email protected]

jobs:
test:
executor:
name: node/default

steps:
- checkout

- node/with-cache:
steps:
- run: npm install
- run: make test-coverage

# More compact variant without hashsum check
# - run: curl -sL https://coveralls.io/coveralls-linux.tar.gz | tar -xz && ./coveralls
- run: |
curl -sLO https://github.com/coverallsapp/coverage-reporter/releases/latest/download/coveralls-linux.tar.gz
curl -sLO https://github.com/coverallsapp/coverage-reporter/releases/latest/download/coveralls-checksums.txt
cat coveralls-checksums.txt | grep coveralls-linux.tar.gz | sha256sum --check
tar -xzf coveralls-linux.tar.gz
./coveralls
workflows:
test:
jobs:
- test
14 changes: 10 additions & 4 deletions examples/focus_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,19 @@

def run_example():
"""
Runs an example workflow to showcase the usage of different functions and modules.
Runs an example workflow to showcase the
usage of different functions and modules.
This function generates example data, standardizes the features, trains a decision tree model,
performs perturbation using the FOCUS algorithm, and visualizes the results using PCA plots.
This function
- generates example data
- standardizes the features
- trains a decision tree model
- performs perturbation using the FOCUS algorithm
- visualizes the results using PCA plots
Returns:
None: This function displays the plots but does not return any value.
None: This function displays the plots
but does not return any value.
"""
start_time = time.time()

Expand Down
24 changes: 17 additions & 7 deletions examples/hyperparameter_tuning_example.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,37 @@
import optuna
import tensorflow as tf
from utils import generate_example_data, standardize_features, train_decision_tree_model
from utils import (
generate_example_data,
standardize_features,
train_decision_tree_model,
)

from focus import Focus


def objective(trial):
"""
This function is an objective function for hyperparameter tuning using optuna.
It explores the hyperparameter sets and evaluates the result on a given model and dataset
Mean distance and number of unchanged instances are used for the evaluation.
This function is an objective function for
hyperparameter tuning using optuna.
It explores the hyperparameter sets and evaluates the result on a
given model and dataset
Mean distance and number of unchanged instances are
used for the evaluation.
Args:
trial (optuna.Trial): Object that contains information about the current trial,
including hyperparameters.
trial (optuna.Trial):
Object that contains information about the current trial,
including hyperparameters.
Returns:
Mean CFE distance + number of unchanged instances squared -
This is the objective function for hyperparameter optimization
* Note: typically we want to minimise a number of unchanged first,
so penalising the score by having squared number.
Also, to not distort this objective, having the mean distance divided by 100.
Also, to not distort this objective,
having the mean distance divided by 100.
"""
X_train, X_test, y_train, y_test = generate_example_data(1000)
X_train, X_test = standardize_features(X_train, X_test)
Expand Down
Loading

0 comments on commit 405619c

Please sign in to comment.