Package: arules
Arules - multi-purpose association rulesArules 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).InstallationPython 3.6+ | Linux, Mac OS X, Windowspipinstall-UarulesGetting StartedLet's create some association rules over some tabular dataimportpandasaspdanes96=pd.read_csv("anes96.csv")anes96.head()|popul|TVnews|selfLR|ClinLR|DoleLR|PID|age|educ|income|vote|logpopul||-------|--------|------------------------|-------------------|-----------------------|------------------|------|----------------------|--------------------------|---------|--------------------||0.0|7.0|ExtremelyConservative|Extremelyliberal|Conservative|StrongRepublica|36.0|Highschoolgraduate|Noneorlessthan$2,999|Dole|-2.302585092994045||190.0|1.0|Slightlyliberal|Slightlyliberal|Slightlyconservative|WeakDemocrat|20.0|Somecollege|Noneorlessthan$2,999|Clinton|5.247550249494384||31.0|7.0|Liberal|Liberal|Conservative|WeakDemocrat|24.0|Master's degree      | None or less than $2,999 | Clinton | 3.4372078191851885 ||83.0|4.0|Slightlyliberal|Moderate|Slightlyconservative|WeakDemocrat|28.0|Master's degree      | None or less than $2,999 | Clinton | 4.4200447018614035 ||640.0|7.0|Slightlyconservative|Conservative|Moderate|StrongDemocrat|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 interestimportarulesasarfromarules.utilsimportfive_quantile_based_bins,top_bottom_10,top_5_variant_variablesrules,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 purposesar.present_rules_per_consequent(rules,consequent={'vote':'Clinton'},selection_function=top_5_variant_variables,drop_dups=True,plot=True)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.ContributingPlease readCONTRIBUTING.mdfor details on our code of conduct, and the process for submitting pull requests to us.VersioningWe useSemVerfor versioning. For the versions available.AuthorsAbir Koren-Initial work-WindWardLicenseThis project is licensed under the MIT License - see theLICENSE.mdfile for details