Skip to main content

A simple Python 3 wrapper around L3 binaries.

Project description

l3wrapper
=========

|pypi badge| |docs badge| |doi badge|

.. |pypi badge| image:: https://img.shields.io/pypi/v/l3wrapper.svg
:target: https://pypi.python.org/pypi/l3wrapper
:alt: Latest PyPI version

.. |Docs Badge| image:: https://readthedocs.org/projects/l3wrapper/badge/
:alt: Documentation Status
:scale: 100%
:target: http://l3wrapper.readthedocs.io

.. |doi badge| image:: https://zenodo.org/badge/244676535.svg
:target: https://zenodo.org/badge/latestdoi/244676535

.. .. image:: https://travis-ci.org/borntyping/cookiecutter-pypackage-minimal.png
.. :target: https://travis-ci.org/borntyping/cookiecutter-pypackage-minimal
.. :alt: Latest Travis CI build status

A Python 3 wrapper around Live-and-Let-Live (``L^3``) classifier binaries implementing the ``scikit-learn`` estimator interface. The associative classifier was originally published in [#]_.

When imported, the package looks for ``L^3`` compiled binaries in the user's ``$HOME`` directory. If they are not found, it downloads them.
If you mind letting the wrapper do this for you, you can download the binaries for `macOS Catalina <https://dbdmg.polito.it/wordpress/wp-content/uploads/2020/02/L3C_osx1015.zip>`_ or `Ubuntu 18.04 <https://dbdmg.polito.it/wordpress/wp-content/uploads/2020/03/L3C_ubuntu1804.zip>`_.


.. [#] Elena Baralis, Silvia Chiusano, and Paolo Garza. 2008. A Lazy Approach to Associative Classification. IEEE Trans. Knowl. Data Eng. 20, 2 (2008), 156–171. https://doi.org/10.1109/TKDE.2007.190677

Installation
------------
Install using `pip <http://www.pip-installer.org/en/latest/>`__ with:

::

pip install l3wrapper

Or, `download a wheel or source archive from
PyPI <https://pypi.python.org/pypi/l3wrapper>`__.

Requirements
^^^^^^^^^^^^

The package is dependent on ``numpy``, ``scikit-learn``, ``tqdm``, and ``requests``.


Usage
-----
By design, the classifier **is intended for categorical/discrete attributes**. Therefore, using subtypes of ``numpy.number`` to fit the model is not allowed.

Simple classification
^^^^^^^^^^^^^^^^^^^^^

A sample usage with the `Car Evaluation dataset <https://archive.ics.uci.edu/ml/datasets/Car+Evaluation>`_:

>>> from l3wrapper.l3wrapper import L3Classifier
>>> import numpy as np
>>> from sklearn.model_selection import train_test_split
>>> from sklearn.metrics import accuracy_score
>>> X = np.loadtxt('car.data', dtype=object, delimiter=',')
>>> y = X[:, -1]
>>> X = X[:, :-1]
>>> X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42)
>>> clf = L3Classifier().fit(X_train, y_train)
>>> accuracy_score(y_test, clf.predict(X_test))
0.9071803852889667

Column names and interpretable rules
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Use the ``column_names`` and ``save_human_readable`` parameters to obtain an interpretable representation of the model:

>>> column_names = ['buying', 'maint', 'doors', 'persons', 'lug_boot', 'safety']
>>> clf = L3Classifier().fit(X_train, y_train, column_names=column_names, save_human_readable=True)

The snippet will generate the *level1* and *level2* rule sets. An excerpt is:

::

0 persons:4,safety:high,maint:low,buying:high acc 12 100.0 4
1 doors:2,buying:vhigh,safety:med,lug_boot:med unacc 11 100.0 4

in the form::

<rule_id>\t<antecedent>\t<class label>\t<support count>\t<confidence(%)>\t<rule length>


Known limitations
-----------------

- **fixed** *The parallel training of multiple models cause failures (e.g. using ``GridSearchCV``, ``joblib`` or custom parallelism through ``multiprocessing`` with ``njobs>1``).*
- The scikit-learn's utility ``check_estimator`` still doesn't work, as
L3Classifier doesn't support numerical input.

Compatibility
-------------

The underlying ``L^3`` binaries are currently available for **macOS and Ubuntu**.

The package is currently tested with Python 3.6+.

License
-------

The MIT `License <https://github.com/g8a9/l3wrapper/blob/master/LICENSE>`_.

Authors
-------

`l3wrapper` was written by `g8a9 <giuseppe.attanasio@polito.it>`_.


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

l3wrapper-0.7.0.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

l3wrapper-0.7.0-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file l3wrapper-0.7.0.tar.gz.

File metadata

  • Download URL: l3wrapper-0.7.0.tar.gz
  • Upload date:
  • Size: 13.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1.post20200622 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

File hashes

Hashes for l3wrapper-0.7.0.tar.gz
Algorithm Hash digest
SHA256 33ca2fb2e4232f91ca7482ccefcd06f00c4c1cf69ac00311e1b253f2a85b2610
MD5 a90c54ef038ef93611aaa0f6285727b2
BLAKE2b-256 d9e56a8e639defb0b7deb9d5958dfb472956ade3fa323806ebacbc32ec2abdb7

See more details on using hashes here.

File details

Details for the file l3wrapper-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: l3wrapper-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 16.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1.post20200622 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

File hashes

Hashes for l3wrapper-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 544c139489ffc76aea175ae36779443f261f64ae04e352327ba3732ec8319a91
MD5 b265d2f9eb0a07123fbe1067d14ce6c8
BLAKE2b-256 86a4f18d0ecb4009a130d9541d6e1507251b212d773dc99542c224f24ba70d52

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page