{"id":17606514,"url":"https://github.com/mhahsler/arulespy","last_synced_at":"2026-01-08T00:34:12.314Z","repository":{"id":163746840,"uuid":"639185668","full_name":"mhahsler/arulespy","owner":"mhahsler","description":"Python interface to arules for association rule mining","archived":false,"fork":false,"pushed_at":"2023-10-10T20:16:56.000Z","size":9975,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-05T17:24:57.449Z","etag":null,"topics":["association-rules","frequent-pattern-mining"],"latest_commit_sha":null,"homepage":"https://mhahsler.github.io/arulespy/","language":"TeX","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mhahsler.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-11T00:21:45.000Z","updated_at":"2025-02-04T18:03:36.000Z","dependencies_parsed_at":"2023-10-04T09:08:16.303Z","dependency_job_id":"2d9774bc-2736-4378-bee7-b70b06866c54","html_url":"https://github.com/mhahsler/arulespy","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":"tomchen/example_pypi_package","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mhahsler%2Farulespy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mhahsler%2Farulespy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mhahsler%2Farulespy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mhahsler%2Farulespy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mhahsler","download_url":"https://codeload.github.com/mhahsler/arulespy/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246254148,"owners_count":20747949,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["association-rules","frequent-pattern-mining"],"created_at":"2024-10-22T15:44:42.254Z","updated_at":"2026-01-08T00:34:12.285Z","avatar_url":"https://github.com/mhahsler.png","language":"TeX","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Python interface to the R package arules\n\n[![PyPI\npackage](https://img.shields.io/badge/pip%20install-arulespy-brightgreen)](https://pypi.org/project/arulespy/)\n[![version\nnumber](https://img.shields.io/pypi/v/arulespy?color=green\u0026label=version)](https://github.com/mhahsler/arulespy/releases)\n[![Actions\nStatus](https://github.com/mhahsler/arulespy/workflows/Test/badge.svg)](https://github.com/mhahsler/arulespy/actions)\n[![License](https://img.shields.io/github/license/mhahsler/arulespy)](https://github.com/mhahsler/arulespy/blob/main/LICENSE)\n\n`arulespy` is a Python module available from [PyPI](https://pypi.org/project/arulespy/).\nThe `arules` module in `arulespy` provides an easy to install Python interface to the \n[R package arules](https://github.com/mhahsler/arules) for association rule mining built \nwith [`rpy2`](https://pypi.org/project/rpy2/). \n\nThe R arules package implements a comprehensive\ninfrastructure for representing, manipulating and analyzing transaction data and patterns using frequent itemsets and association rules. \nThe package also provides a wide range of interest measures and mining algorithms including the code of Christian Borgelt’s popular \nand efficient C implementations of the association mining algorithms Apriori and Eclat,\nand optimized C/C++ code for \nmining and manipulating association rules using sparse matrix representation. \n\nThe `arulesViz` module provides `plot()` for visualizing association rules using\nthe [R package arulesViz](https://github.com/mhahsler/arulesViz).\n\n`arulespy` provides Python classes\nfor\n\n-   `Transactions`: Convert pandas dataframes into transaction data\n-   `Rules`: Association rules\n-   `Itemsets`: Itemsets\n-   `ItemMatrix`: sparse matrix representation of sets of items.\n\nwith Phyton-style slicing and `len()`. \n\nMost arules functions are\ninterfaced as methods for the four classes with conversion from the R data structures to Python.\nDocumentation is avaialible in Python via `help()`. Detailed online documentation\nfor the R package is available [here](https://mhahsler.r-universe.dev/arules/doc/manual.html). \n\nLow-level `arules` functions can also be directly used in the form \n`R.\u003carules R function\u003e()`. The result will be a `rpy2` data type.\nTransactions, itemsets and rules can manually be converted to Python\nclasses using the helper function `a2p()`.\n\nTo cite the Python module ‘arulespy’ in publications use:\n\n\u003e Michael Hahsler. ARULESPY: Exploring association rules and frequent itemsets in Python. arXiv:2305.15263 [cs.DB], May 2023. DOI: [10.48550/arXiv.2305.15263](https://doi.org/10.48550/arXiv.2305.15263)\n\n\n## Installation\n\n`arulespy` is based on the python package `rpy2` which requires an R installation. Here are the installation steps:\n\n1. Install the latest version of R (\u003e4.0) from https://www.r-project.org/\n\n2. Install required libraries on your OS:\n   - libcurl is needed by R package [curl](https://cran.r-project.org/web/packages/curl/index.html).\n      - Ubuntu: `sudo apt-get install libcurl4-openssl-dev`\n      - MacOS: `brew install curl`\n      - Windows: no installation necessary, but read the Windows section below.\n\n3. Install `arulespy` which will automatically install `rpy2` and `pandas`.\n    ``` sh\n    pip install arulespy\n    ```\n\n4. Optional: Set the environment variable `R_LIBS_USER` to decide where R packages are stored \n    (see [libPaths()](https://stat.ethz.ch/R-manual/R-devel/library/base/html/libPaths.html) for details). If not set then R will determine a suitable location.\n\n5. Optional: `arulespy` will install the needed R packages when it is imported for the first time.\n    This may take a while. R packages can also be preinstalled. Start R and run \n    `install.packages(c(\"arules\", \"arulesViz\"))`\n\n\nThe most likely issue is that `rpy2` does not find R or R's shared library. \nThis will lead the python kernel to die or exit without explanation when the package `arulespy` is imported.\nCheck `python -m rpy2.situation` to see if R and R's libraries are found.\nIf you use iPython notebooks then you can include the following code block in your notebook to check:\n```python\nfrom rpy2 import situation\n\nfor row in situation.iter_info():\n    print(row)\n```\n\nThe output should include a line saying `Loading R library from rpy2: OK`.\n\n### Note for Windows users\n `rpy2` currently does not fully support Windows and the installation is somewhat tricky. I was able to use it with the following setup:\n\n* Windows 10\n* rpy2 version 3.5.14\n* Python version 3.10.12\n* R version 4.3.1\n\nI use the following code to set the needed environment variables needed by Windows \nbefore I import from `arulespy`\n```python\nfrom rpy2 import situation\nimport os\n\nr_home = situation.r_home_from_registry()\nr_bin = r_home + '\\\\bin\\\\x64\\\\'\nos.environ['R_HOME'] = r_home\nos.environ['PATH'] =  r_bin + \";\" + os.environ['PATH']\nos.add_dll_directory(r_bin)\n\nfor row in situation.iter_info():\n    print(row)\n```\n\nThe output should include a line saying `Loading R library from rpy2: OK`\n\nMore information on installing `rpy2` can be found [here](https://pypi.org/project/rpy2/).\n\n\n## Example\n\n```python\nfrom arulespy.arules import Transactions, apriori, parameters\nimport pandas as pd\n\n# define the data as a pandas dataframe\ndf = pd.DataFrame (\n    [\n        [True,True, True],\n        [True, False,False],\n        [True, True, True],\n        [True, False, False],\n        [True, True, True]\n    ],\n    columns=list ('ABC')) \n\n# convert dataframe to transactions\ntrans = transactions.from_df(df)\n\n# mine association rules\nrules = apriori(trans,\n                    parameter = parameters({\"supp\": 0.1, \"conf\": 0.8}), \n                    control = parameters({\"verbose\": False}))  \n\n# display the rules as a pandas dataframe\nrules.as_df()\n```\n\n|    | LHS   | RHS   |   support |   confidence |   coverage |   lift |   count |\n|---:|:------|:------|----------:|-------------:|-----------:|-------:|--------:|\n|  1 | {}    | {A}   |       0.8 |          0.8 |        1   |   1    |       8 |\n|  2 | {}    | {C}   |       0.8 |          0.8 |        1   |   1    |       8 |\n|  3 | {B}   | {A}   |       0.4 |          0.8 |        0.5 |   1    |       4 |\n|  4 | {B}   | {C}   |       0.5 |          1   |        0.5 |   1.25 |       5 |\n|  5 | {A,B} | {C}   |       0.4 |          1   |        0.4 |   1.25 |       4 |\n|  6 | {B,C} | {A}   |       0.4 |          0.8 |        0.5 |   1    |       4 |\n\nComplete examples:\n  * [Using arules](https://mhahsler.github.io/arulespy/examples/arules.html)\n  * [Using arulesViz](https://mhahsler.github.io/arulespy/examples/arulesViz.html)\n\n\n## References\n\n- Michael Hahsler. [ARULESPY: Exploring association rules and frequent itemsets in \n  Python.](http://dx.doi.org/10.48550/arXiv.2305.15263) arXiv:2305.15263 [cs.DB], May 2023. \n  DOI: 10.48550/arXiv.2305.15263\n- Michael Hahsler, Sudheer Chelluboina, Kurt Hornik, and Christian\n  Buchta. [The arules R-package ecosystem: Analyzing interesting\n  patterns from large transaction\n  datasets.](https://jmlr.csail.mit.edu/papers/v12/hahsler11a.html)\n  *Journal of Machine Learning Research,* 12:1977-1981, 2011.\n- Michael Hahsler, Bettina Grün and Kurt Hornik. [arules - A\n  Computational Environment for Mining Association Rules and Frequent\n  Item Sets.](https://dx.doi.org/10.18637/jss.v014.i15) *Journal of\n  Statistical Software,* 14(15), 2005. DOI: 10.18637/jss.v014.i15\n- Hahsler, Michael. [A Probabilistic Comparison of Commonly Used\n  Interest Measures for Association\n  Rules](https://mhahsler.github.io/arules/docs/measures), 2015, URL:\n  \u003chttps://mhahsler.github.io/arules/docs/measures\u003e.\n- Michael Hahsler. [An R Companion for Introduction to Data Mining:\n  Chapter\n  5](https://mhahsler.github.io/Introduction_to_Data_Mining_R_Examples/book/association-analysis-basic-concepts-and-algorithms.html),\n  2021, URL:\n  \u003chttps://mhahsler.github.io/Introduction_to_Data_Mining_R_Examples/book/\u003e\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmhahsler%2Farulespy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmhahsler%2Farulespy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmhahsler%2Farulespy/lists"}