Giter Site home page Giter Site logo

fasttrees / fasttrees Goto Github PK

View Code? Open in Web Editor NEW
12.0 4.0 6.0 188 KB

A fast and frugal tree classifier for sklearn

Home Page: https://fasttrees.github.io/fasttrees/

License: MIT License

Python 100.00%
data-analytics data-science machine-learning python python3 statistics tree-classifiers binary-classification classification

fasttrees's Introduction

fasttrees

Packages and Releases PyPI - Version
Build Status Upload Python Package to TestPyPI Upload Python Package to PyPI Python package pyling: workflow
Test Coverage codecov
Other Information Downloads PyPI - Python Version linting: pylint REUSE status

|

A fast-and-frugal-tree classifier based on Python's scikit learn.

Fast-and-frugal trees are classification trees that are especially useful for making decisions under uncertainty. Due their simplicity and transparency they are very robust against noise and errors in data. They are one of the heuristics proposed by Gerd Gigerenzer in Fast and Frugal Heuristics in Medical Decision. This particular implementation is based on on the R package FFTrees, developed by Phillips, Neth, Woike and Grassmaier.

Install

You can install fasttrees using

pip install fasttrees

Quick first start

Below we provide a qick first start example with fast-and-frugal trees. We use the popular iris flower data set (also known as the Fisher's Iris data set), split it into a train and test data set, and fit a fast-and-frugal tree classifier on the training data set. Finally, we get the score on the test data set.

from sklearn import datasets, model_selection

from fasttrees import FastFrugalTreeClassifier


# Load data set
iris_dict = datasets.load_iris(as_frame=True)

# Load training data, preprocess it by transforming y into a binary classification problem, and
# split into train and test data set
X_iris, y_iris = iris_dict['data'], iris_dict['target']
y_iris = y_iris.apply(lambda entry: entry in [0, 1]).astype(bool)
X_train_iris, X_test_iris, y_train_iris, y_test_iris = model_selection.train_test_split(
    X_iris, y_iris, test_size=0.4, random_state=42)

# Fit and test fitted tree
fftc = FastFrugalTreeClassifier()
fftc.fit(X_train_iris, y_train_iris)
fftc.score(X_test_iris, y_test_iris)

fasttrees's People

Contributors

dominiczy avatar macos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

fasttrees's Issues

Dependencies problem with Python 3.12.3 on Ubuntu

I'm having a problem installing fasttrees 1.3.1 on my local Ubuntu machine with Python 3.12.3. I can't also install it on Google Colab. Is there a conflict with Python 3.12? It looks like 'distutils' module has been deprecated. I'm new to Python, so any help would be greatly appreciated.

(venv) $ pip install fasttrees
ERROR: Exception:
Traceback (most recent call last):
  File "/venv/lib/python3.12/site-packages/pip/_internal/cli/base_command.py", line 180, in exc_logging_wrapper
    status = run_func(*args)
             ^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/pip/_internal/cli/req_command.py", line 245, in wrapper
    return func(self, options, args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/pip/_internal/commands/install.py", line 377, in run
    requirement_set = resolver.resolve(
                      ^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/resolver.py", line 95, in resolve
    result = self._result = resolver.resolve(
                            ^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/pip/_vendor/resolvelib/resolvers.py", line 546, in resolve
    state = resolution.resolve(requirements, max_rounds=max_rounds)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/pip/_vendor/resolvelib/resolvers.py", line 427, in resolve
    failure_causes = self._attempt_to_pin_criterion(name)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/pip/_vendor/resolvelib/resolvers.py", line 239, in _attempt_to_pin_criterion
    criteria = self._get_updated_criteria(candidate)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/pip/_vendor/resolvelib/resolvers.py", line 230, in _get_updated_criteria
    self._add_to_criteria(criteria, requirement, parent=candidate)
  File "/venv/lib/python3.12/site-packages/pip/_vendor/resolvelib/resolvers.py", line 173, in _add_to_criteria
    if not criterion.candidates:
           ^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/pip/_vendor/resolvelib/structs.py", line 156, in __bool__
    return bool(self._sequence)
           ^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/found_candidates.py", line 155, in __bool__
    return any(self)
           ^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/found_candidates.py", line 143, in <genexpr>
    return (c for c in iterator if id(c) not in self._incompatible_ids)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/found_candidates.py", line 47, in _iter_built
    candidate = func()
                ^^^^^^
  File "/venv/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/factory.py", line 182, in _make_candidate_from_link
    base: Optional[BaseCandidate] = self._make_base_candidate_from_link(
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/factory.py", line 228, in _make_base_candidate_from_link
    self._link_candidate_cache[link] = LinkCandidate(
                                       ^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 290, in __init__
    super().__init__(
  File "/venv/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 156, in __init__
    self.dist = self._prepare()
                ^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 222, in _prepare
    dist = self._prepare_distribution()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 301, in _prepare_distribution
    return preparer.prepare_linked_requirement(self._ireq, parallel_builds=True)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/pip/_internal/operations/prepare.py", line 525, in prepare_linked_requirement
    return self._prepare_linked_requirement(req, parallel_builds)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/pip/_internal/operations/prepare.py", line 640, in _prepare_linked_requirement
    dist = _get_prepared_distribution(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/pip/_internal/operations/prepare.py", line 71, in _get_prepared_distribution
    abstract_dist.prepare_distribution_metadata(
  File "/venv/lib/python3.12/site-packages/pip/_internal/distributions/sdist.py", line 54, in prepare_distribution_metadata
    self._install_build_reqs(finder)
  File "/venv/lib/python3.12/site-packages/pip/_internal/distributions/sdist.py", line 124, in _install_build_reqs
    build_reqs = self._get_build_requires_wheel()
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/pip/_internal/distributions/sdist.py", line 101, in _get_build_requires_wheel
    return backend.get_requires_for_build_wheel()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/pip/_internal/utils/misc.py", line 745, in get_requires_for_build_wheel
    return super().get_requires_for_build_wheel(config_settings=cs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_impl.py", line 166, in get_requires_for_build_wheel
    return self._call_hook('get_requires_for_build_wheel', {
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_impl.py", line 321, in _call_hook
    raise BackendUnavailable(data.get('traceback', ''))
pip._vendor.pyproject_hooks._impl.BackendUnavailable: Traceback (most recent call last):
  File "/venv/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 77, in _build_backend
    obj = import_module(mod_path)
          ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1310, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 995, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/tmp/pip-build-env-8j8aynnv/overlay/lib/python3.12/site-packages/setuptools/__init__.py", line 9, in <module>
    import distutils.core
ModuleNotFoundError: No module named 'distutils'

Dependancies conflict and resulting

Steps to reproduce the issue:

  • virtual environment on vscode specifying python 3.8: conda create --name myenv python=3.8
  • activate the environment: conda activate myenv
  • install fasttrees version 1.3.1: pip install fasttrees==1.3.1
  • returns error:
     Traceback (most recent call last):
        File "<string>", line 196, in check_package_status
        File "/Users/ec531/anaconda3/envs/myenv/lib/python3.8/importlib/__init__.py", line 127, in import_module
          return _bootstrap._gcd_import(name[level:], package, level)
        File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
        File "<frozen importlib._bootstrap>", line 991, in _find_and_load
        File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
        File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
        File "<frozen importlib._bootstrap_external>", line 843, in exec_module
        File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
        File "/private/var/folders/r8/909lcpq95llgcgh0d12nblw80000gq/T/pip-build-env-8owjeyyn/overlay/lib/python3.8/site-packages/numpy/__init__.py", line 142, in <module>
          from . import core
        File "/private/var/folders/r8/909lcpq95llgcgh0d12nblw80000gq/T/pip-build-env-8owjeyyn/overlay/lib/python3.8/site-packages/numpy/core/__init__.py", line 47, in <module>
          raise ImportError(msg)
      ImportError:
      
      IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
      
      Importing the numpy c-extensions failed.
      - Try uninstalling and reinstalling numpy.
      - If you have already done that, then:
        1. Check that you expected to use Python3.8 from "/Users/ec531/anaconda3/envs/myenv/bin/python",
           and that you have no directories in your PATH or PYTHONPATH that can
           interfere with the Python and numpy version "1.17.3" you're trying to use.
        2. If (1) looks fine, you can open a new issue at
           https://github.com/numpy/numpy/issues.  Please include details on:
           - how you installed Python
           - how you installed numpy
           - your operating system
           - whether or not you have multiple versions of Python installed
           - if you built from source, your compiler versions and ideally a build log
      
      - If you're working with a numpy git repository, try `git clean -xdf`
        (removes all files not under version control) and rebuild numpy.
      
      Note: this error has many possible causes, so please don't comment on
      an existing issue about this - open a new one instead.

Original error was:

        Referenced from: <3D18DA7D-E386-3EA8-9904-D32F6244D727> /private/var/folders/r8/909lcpq95llgcgh0d12nblw80000gq/T/pip-build-env-8owjeyyn/overlay/lib/python3.8/site-packages/numpy/core/_multiarray_umath.cpython-38-darwin.so
        Reason: tried: '/Users/ec531/anaconda3/envs/myenv/bin/../lib/libopenblas.0.dylib' (no such file), '/Users/ec531/anaconda3/envs/myenv/bin/../lib/libopenblas.0.dylib' (no such file)
      
      Traceback (most recent call last):
        File "/Users/ec531/anaconda3/envs/myenv/lib/python3.8/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "/Users/ec531/anaconda3/envs/myenv/lib/python3.8/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "/Users/ec531/anaconda3/envs/myenv/lib/python3.8/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 251, in build_wheel
          return _build_backend().build_wheel(wheel_directory, config_settings,
        File "/private/var/folders/r8/909lcpq95llgcgh0d12nblw80000gq/T/pip-build-env-8owjeyyn/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 404, in build_wheel
          return self._build_with_temp_dir(
        File "/private/var/folders/r8/909lcpq95llgcgh0d12nblw80000gq/T/pip-build-env-8owjeyyn/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 389, in _build_with_temp_dir
          self.run_setup()
        File "/private/var/folders/r8/909lcpq95llgcgh0d12nblw80000gq/T/pip-build-env-8owjeyyn/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 480, in run_setup
          super(_BuildMetaLegacyBackend, self).run_setup(setup_script=setup_script)
        File "/private/var/folders/r8/909lcpq95llgcgh0d12nblw80000gq/T/pip-build-env-8owjeyyn/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 311, in run_setup
          exec(code, locals())
        File "<string>", line 304, in <module>
        File "<string>", line 292, in setup_package
        File "<string>", line 220, in check_package_status
      ImportError: numpy is not installed.
      scikit-learn requires numpy >= 1.13.3.
      Installation instructions are available on the scikit-learn website: http://scikit-learn.org/stable/install.html
      
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for scikit-learn
Failed to build numpy pandas scikit-learn
ERROR: Could not build wheels for numpy, pandas, scikit-learn, which is required to install pyproject.toml-based projects

Full install log is attached.

Does not work, package issues.

I ve tried pip install fasttrees, installed 1.2.5 version and when I do import I get the following import error.

`

from fasttrees.fasttrees import FastFrugalTreeClassifier
Traceback (most recent call last):
File "", line 1, in
File "/home/m/repo/fasttrees/fasttrees/fasttrees.py", line 5, in
from sklearn.metrics.scorer import balanced_accuracy_score
ModuleNotFoundError: No module named 'sklearn.metrics.scorer'
`

is this project sill alive?

TypeError: __new__() got an unexpected keyword argument 'labels'

Hello!

I'm running the exact same example of the Classifier using the credit approval dataset. I am converting the column A15 to a boolean (as per the same exact steps). Encountering the following error when I fit the Classifier:

pooja@LAPTOP-LHD6FNOA:~/FastFrugalTrees$ python3 fftrees_v1.py
Traceback (most recent call last):
File "fftrees_v1.py", line 29, in
fc.fit(X_train, y_train)
File "/home/pooja/.local/lib/python3.8/site-packages/fasttrees/fasttrees.py", line 293, in fit
self._get_thresholds(X, y)
File "/home/pooja/.local/lib/python3.8/site-packages/fasttrees/fasttrees.py", line 64, in _get_thresholds
midx = pd.MultiIndex(levels=[[], []],
TypeError: new() got an unexpected keyword argument 'labels'

Please help me out with this. Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.