Skip to main content

Arules - multi-purpose association rules

Arules is an open-source python package for association rules creation. It allows creation of association rules over tabular data (pandas dataframe). While standard association rules require transactional data, arules considers association rules as an analysis utility for categorical data. The Package also supports association rules over continuous data by application of binning methods (some basic methods are included in the package but users can define their own binning functions).

Installation

Python 3.6+ | Linux, Mac OS X, Windows

pip install -U arules

Getting Started

Let's create some association rules over some tabular data

import pandas as pd

anes96 = pd.read_csv("anes96.csv")
anes96.head()

| popul | TVnews | selfLR                 | ClinLR            | DoleLR                | PID              | age  | educ                 | income                   | vote    | logpopul           |
|-------|--------|------------------------|-------------------|-----------------------|------------------|------|----------------------|--------------------------|---------|--------------------|
| 0.0   | 7.0    | Extremely Conservative | Extremely liberal | Conservative          | Strong Republica | 36.0 | High school graduate | None or less than $2,999 | Dole    | -2.302585092994045 |
| 190.0 | 1.0    | Slightly liberal       | Slightly liberal  | Slightly conservative | Weak Democrat    | 20.0 | Some college         | None or less than $2,999 | Clinton | 5.247550249494384  |
| 31.0  | 7.0    | Liberal                | Liberal           | Conservative          | Weak Democrat    | 24.0 | Master's degree      | None or less than $2,999 | Clinton | 3.4372078191851885 |
| 83.0  | 4.0    | Slightly liberal       | Moderate          | Slightly conservative | Weak Democrat    | 28.0 | Master's degree      | None or less than $2,999 | Clinton | 4.4200447018614035 |
| 640.0 | 7.0    | Slightly conservative  | Conservative      | Moderate              | Strong Democrat  | 68.0 | Master's degree      | None or less than $2,999 | Clinton | 6.461624414147957  |

Note that the table contains both categorical and continuous fields (which can be handled using a selected binning method). Now we use arules to extract association rules according to a specification of interest

import arules as ar
from arules.utils import five_quantile_based_bins, top_bottom_10, top_5_variant_variables

rules, supp_dict = ar.create_association_rules(anes96,max_cols=2,binning_method=five_quantile_based_bins)

After the calculation is done we can present rules of selection for analysis purposes

ar.present_rules_per_consequent(rules,consequent={'vote':'Clinton'},
                                selection_function=top_5_variant_variables, drop_dups=True,
                                plot=True)

PID rules selfLR rules ClinLR rules DoleLR rules Income rules

As we set the consequent to be: {'vote':'Clinton'}, the presented rules reflect the likelihood of an individual to vote for clinton given the respective feature. For example, if we consider the income variable above, a person with an income of 3,000-4,999 (which populates, according to the barchart, 1% of the sample) is approximately 1.6 times more likely (w.r.t. the average) to vote for Clinton, while a person with an income of 90,000-104,999 (which populates, according to the barchart, 4% of the sample) is approximately 1.4 times less likely to vote for Clinton.

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available.

Authors

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Metadata

Release files for arules 0.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for arules 0.0.0
File Size Uploaded Provenance Actions
arules-0.0.0.tar.gz 16.3 kB Without provenance Details for arules-0.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for arules 0.0.0
File Interpreter ABI Platform Actions
arules-0.0.0-py3-none-any.whl Python 3 none any Details for arules-0.0.0-py3-none-any.whl

Total release size: 34.2 kB

Release files / arules-0.0.0.tar.gz

Download URL arules-0.0.0.tar.gz
Size 16.3 kB
Tags Source
SHA-256 checksum
How to use checksums
a4a437679b810f144cc16cc451090c78251a8c6fd26bdfaa63ad502db73fba79
BLAKE2b-256 checksum
How to use checksums
c8386838990ca068f9df021af270f47ddac3b5cac1eb59cc653ed552404ba84c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.8

Release files / arules-0.0.0-py3-none-any.whl

Download URL arules-0.0.0-py3-none-any.whl
Size 17.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
766bcdb169e9dd3303346c196bd4c734dc631d04c5ca8a2c5e4f27af07d9c97b
BLAKE2b-256 checksum
How to use checksums
412c5759ba98957f791a689e0f255f56f88b344fca892dcdf7d4bedf9bd3ab65
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.8

Security for arules 0.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page