Skip to main content

The package for action rules mining using Action-Apriori (Apriori Modified for Action Rules Mining)..

Project description

Action Rules

pypi python Build Status codecov

The package for action rules mining using Action-Apriori (Apriori Modified for Action Rules Mining).

Installation

$ pip install action-rules

Features

Action Rules API

# Import Module
from action_rules import ActionRules
import pandas as pd

# Get Data
transactions = {'Sex': ['M', 'F', 'M', 'M', 'F', 'M', 'F'],
                'Age': ['Y', 'Y', 'O', 'Y', 'Y', 'O', 'Y'],
                'Class': [1, 1, 2, 2, 1, 1, 2],
                'Embarked': ['S', 'C', 'S', 'C', 'S', 'C', 'C'],
                'Survived': [1, 1, 0, 0, 1, 1, 0],
                }
data = pd.DataFrame.from_dict(transactions)
# Initialize ActionRules Miner with Parameters
stable_attributes = ['Age', 'Sex']
flexible_attributes = ['Embarked', 'Class']
target = 'Survived'
min_stable_attributes = 2
min_flexible_attributes = 1  # min 1
min_undesired_support = 1
min_undesired_confidence = 0.5  # min 0.5
min_desired_support = 1
min_desired_confidence = 0.5  # min 0.5
undesired_state = '0'
desired_state = '1'
# Action Rules Mining
action_rules = ActionRules(
    min_stable_attributes=min_stable_attributes,
    min_flexible_attributes=min_flexible_attributes,
    min_undesired_support=min_undesired_support,
    min_undesired_confidence=min_undesired_confidence,
    min_desired_support=min_desired_support,
    min_desired_confidence=min_desired_confidence,
    verbose=True
)
# Fit
action_rules.fit(
    data=data,  # cuDF or Pandas Dataframe
    stable_attributes=stable_attributes,
    flexible_attributes=flexible_attributes,
    target=target,
    target_undesired_state=undesired_state,
    target_desired_state=desired_state,
    use_sparse_matrix=True,  # needs SciPy or Cupyx (if use_gpu is True) installed
    use_gpu=False,  # needs Cupy installed
)
# Print rules
# Example: [(Age: O) ∧ (Sex: M) ∧ (Embarked: S → C)] ⇒ [Survived: 0 → 1], support of undesired part: 1, confidence of undesired part: 1.0, support of desired part: 1, confidence of desired part: 1.0, uplift: 1.0
for action_rule in action_rules.get_rules().get_ar_notation():
    print(action_rule)
# Print rules (pretty notation)
# Example: If attribute 'Age' is 'O', attribute 'Sex' is 'M', attribute 'Embarked' value 'S' is changed to 'C', then 'Survived' value '0' is changed to '1 with uplift: 1.0.
for action_rule in action_rules.get_rules().get_pretty_ar_notation():
    print(action_rule)
# JSON export
print(action_rules.get_rules().get_export_notation())

Action Rules CLI

$ action-rules --min_stable_attributes 2 --min_flexible_attributes 1 --min_undesired_support 1 --min_undesired_confidence 0.5 --min_desired_support 1 --min_desired_confidence 0.5 --csv_path 'data.csv' --stable_attributes 'Sex, Age' --flexible_attributes 'Class, Embarked' --target 'Survived' --undesired_state '0' --desired_state '1' --output_json_path 'output.json'

Jupyter Notebook Example

https://github.com/lukassykora/action-rules/blob/main/notebooks/Example.ipynb

Credits

This package was created with Cookiecutter and the waynerv/cookiecutter-pypackage project template.

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

action_rules-0.0.28.tar.gz (21.9 kB view details)

Uploaded Source

Built Distribution

action_rules-0.0.28-py3-none-any.whl (19.7 kB view details)

Uploaded Python 3

File details

Details for the file action_rules-0.0.28.tar.gz.

File metadata

  • Download URL: action_rules-0.0.28.tar.gz
  • Upload date:
  • Size: 21.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for action_rules-0.0.28.tar.gz
Algorithm Hash digest
SHA256 8f2f3369bf48ba4b23db3087e12afe95564ea764f26e0134e949e4fbdaac3fc9
MD5 df9171d4b7adce9c43c4e5e2747abe47
BLAKE2b-256 39b9faf07be8e8fc959fdd8111e7bfe47de9bfb3e90eb7a16ecedee9a156d5df

See more details on using hashes here.

File details

Details for the file action_rules-0.0.28-py3-none-any.whl.

File metadata

File hashes

Hashes for action_rules-0.0.28-py3-none-any.whl
Algorithm Hash digest
SHA256 1f933bdd21a4b4acbfbec788a18e80f4f064e7c378cb4f9d6faaf3760352a1f1
MD5 4dfb6355f4e9263a889a1964f187a99f
BLAKE2b-256 33112e8ab6f3eee506fd3db7f6ffaa023e0eaf639997b1dd3fb75d88556f266b

See more details on using hashes here.

Supported by

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