Skip to main content

Time series numerical association rule mining variants

Project description

logo

Nature-Inspired Algorithms for Time Series Numerical Association Rule Mining

PyPI version PyPI - Python Version PyPI - Downloads Downloads NiaARMTS Documentation status

Repository size License GitHub commit activity Percentage of issues still open Average time to resolve an issue GitHub contributors

✨ Features📦 Installation🚀 Basic example📚 Reference Papers🔑 License📄 Cite us

This framework is designed for numerical association rule mining in time series data using stochastic population-based nature-inspired algorithms[^1]. It provides tools to extract association rules from time series datasets while incorporating key metrics such as support, confidence, inclusion, and amplitude. Although independent from the NiaARM framework, this software can be viewed as an extension, with additional support for time series numerical association rule mining.

[^1]: Fister Jr, I., Yang, X. S., Fister, I., Brest, J., & Fister, D. (2013). A brief review of nature-inspired algorithms for optimization. arXiv preprint arXiv:1307.4186.

✨ Features

The current version of the framework supports two types of time series numerical association rule mining:

  • Fixed Interval Time Series Numerical Association Rule Mining
  • Segmented Interval Time Series Numerical Association Rule Mining

📦 Installation

To install NiaARMTS with pip, use:

pip install niaarmts

🚀 Basic example

Fixed Interval Time Series Numerical Association Rule Mining example

from niapy.algorithms.basic import ParticleSwarmAlgorithm
from niapy.task import Task
from niaarmts import Dataset
from niaarmts.NiaARMTS import NiaARMTS

# Load dataset
dataset = Dataset()
dataset.load_data_from_csv('intervals.csv', timestamp_col='timestamp')

# Create an instance of NiaARMTS
niaarmts_problem = NiaARMTS(
    dimension=dataset.calculate_problem_dimension(),  # Adjust dimension dynamically
    lower=0.0,  # Lower bound of solution space
    upper=1.0,  # Upper bound of solution space
    features=dataset.get_all_features_with_metadata(),  # Pass feature metadata
    transactions=dataset.get_all_transactions(),  # Dataframe containing all transactions
    interval='true',  # Whether we're dealing with interval data
    alpha=1.0,  # Weight for support in fitness calculation
    beta=1.0,  # Weight for confidence in fitness calculation
    gamma=1.0,  # Weight for inclusion in fitness calculation # if 0.0 then inclusion metric is omitted
    delta=1.0  # Weight for amplitude in fitness calculation # if 0.0 then amplitude metric is omitted
)

# Define the optimization task
task = Task(problem=niaarmts_problem, max_iters=100)  # Run for 100 iterations

# Initialize the Particle Swarm Optimization algorithm
pso = ParticleSwarmAlgorithm(population_size=40, min_velocity=-1.0, max_velocity=1.0, c1=2.0, c2=2.0)

# Run the algorithm
best_solution = pso.run(task)

# Save discovered rules to CSV
niaarmts_problem.save_rules_to_csv("interval_rules.csv")

# Print all rules to the terminal
print("\n=== All Identified Rules (Interval Data, Sorted by Fitness) ===")
for idx, rule in enumerate(niaarmts_problem.get_rule_archive(), 1):
    print(f"\nRule #{idx}:")
    print(f"  Antecedent: {rule['antecedent']}")
    print(f"  Consequent: {rule['consequent']}")
    print(f"  Support: {rule['support']:.4f}")
    print(f"  Confidence: {rule['confidence']:.4f}")
    print(f"  Inclusion: {rule['inclusion']:.4f}")
    print(f"  Amplitude: {rule['amplitude']:.4f}")
    print(f"  Fitness: {rule['fitness']:.4f}")
    print(f"  Interval: {rule['start']} (start) to {rule['end']} (end)")

Segmented Interval Time Series Numerical Association Rule Mining example

from niapy.algorithms.basic import ParticleSwarmAlgorithm
from niapy.task import Task
from niaarmts import Dataset
from niaarmts.NiaARMTS import NiaARMTS

# Load dataset
dataset = Dataset()
dataset.load_data_from_csv('ts.csv', timestamp_col='timestamp')

# Create an instance of NiaARMTS
niaarmts_problem = NiaARMTS(
    dimension=dataset.calculate_problem_dimension(),  # Adjust dimension dynamically
    lower=0.0,  # Lower bound of solution space
    upper=1.0,  # Upper bound of solution space
    features=dataset.get_all_features_with_metadata(),  # Pass feature metadata
    transactions=dataset.get_all_transactions(),  # Dataframe containing all transactions
    interval='false',  # Whether we're dealing with interval data
    alpha=1.0,  # Weight for support in fitness calculation
    beta=1.0,  # Weight for confidence in fitness calculation
    gamma=1.0,  # Weight for inclusion in fitness calculation # if 0.0 then inclusion metric is omitted
    delta=1.0  # Weight for amplitude in fitness calculation # if 0.0 then amplitude metric is omitted
)

# Define the optimization task
task = Task(problem=niaarmts_problem, max_iters=100)  # Run for 100 iterations

# Initialize the Particle Swarm Optimization algorithm
pso = ParticleSwarmAlgorithm(population_size=40, min_velocity=-1.0, max_velocity=1.0, c1=2.0, c2=2.0)

# Run the algorithm
best_solution = pso.run(task)

# Output the best solution and its fitness value
print(f"Best solution: {best_solution[0]}")
print(f"Fitness value: {best_solution[1]}")

# Save all discovered rules to a CSV file
niaarmts_problem.save_rules_to_csv("discovered_rules.csv")

# Print all rules to the terminal
print("\n=== All Identified Rules (Sorted by Fitness) ===")
for idx, rule in enumerate(niaarmts_problem.get_rule_archive(), 1):
    print(f"\nRule #{idx}:")
    print(f"  Antecedent: {rule['antecedent']}")
    print(f"  Consequent: {rule['consequent']}")
    print(f"  Support: {rule['support']:.4f}")
    print(f"  Confidence: {rule['confidence']:.4f}")
    print(f"  Inclusion: {rule['inclusion']:.4f}")
    print(f"  Amplitude: {rule['amplitude']:.4f}")
    print(f"  Fitness: {rule['fitness']:.4f}")
    print(f"  Time window: {rule['start']} to {rule['end']}")

📚 Reference Papers

Ideas are based on the following research papers:

[1] Iztok Fister Jr., Dušan Fister, Iztok Fister, Vili Podgorelec, Sancho Salcedo-Sanz. Time series numerical association rule mining variants in smart agriculture. Journal of Ambient Intelligence and Humanized Computing (2023): 1-14.

[2] Iztok Fister Jr., Iztok Fister, Sancho Salcedo-Sanz. Time Series Numerical Association Rule Mining for assisting Smart Agriculture. In: International Conference on Electrical, Computer and Energy Technologies (ICECET). IEEE, 2022.

[3] I. Fister Jr., A. Iglesias, A. Gálvez, J. Del Ser, E. Osaba, I Fister. Differential evolution for association rule mining using categorical and numerical attributes In: Intelligent data engineering and automated learning - IDEAL 2018, pp. 79-88, 2018.

[4] I. Fister Jr., V. Podgorelec, I. Fister. Improved Nature-Inspired Algorithms for Numeric Association Rule Mining. In: Vasant P., Zelinka I., Weber GW. (eds) Intelligent Computing and Optimization. ICO 2020. Advances in Intelligent Systems and Computing, vol 1324. Springer, Cham.

[5] I. Fister Jr., I. Fister A brief overview of swarm intelligence-based algorithms for numerical association rule mining. arXiv preprint arXiv:2010.15524 (2020).

[6] Fister, I. et al. (2020). Visualization of Numerical Association Rules by Hill Slopes. In: Analide, C., Novais, P., Camacho, D., Yin, H. (eds) Intelligent Data Engineering and Automated Learning – IDEAL 2020. IDEAL 2020. Lecture Notes in Computer Science(), vol 12489. Springer, Cham. https://doi.org/10.1007/978-3-030-62362-3_10

[7] I. Fister, S. Deb, I. Fister, Population-based metaheuristics for Association Rule Text Mining, In: Proceedings of the 2020 4th International Conference on Intelligent Systems, Metaheuristics & Swarm Intelligence, New York, NY, USA, mar. 2020, pp. 19–23. doi: 10.1145/3396474.3396493.

[8] I. Fister, I. Fister Jr., D. Novak and D. Verber, Data squashing as preprocessing in association rule mining, 2022 IEEE Symposium Series on Computational Intelligence (SSCI), Singapore, Singapore, 2022, pp. 1720-1725, doi: 10.1109/SSCI51031.2022.10022240.

See also

[1] NiaARM.jl: Numerical Association Rule Mining in Julia

[2] arm-preprocessing: Implementation of several preprocessing techniques for Association Rule Mining (ARM)

🔑 License

This package is distributed under the MIT License. This license can be found online at http://www.opensource.org/licenses/MIT.

Disclaimer

This framework is provided as-is, and there are no guarantees that it fits your purposes or that it is bug-free. Use it at your own risk!

📄 Cite us

[1] Fister, I., Jr.; Salcedo-Sanz, S.; Alexandre-Cortizo, E.; Novak, D.; Fister, I.; Podgorelec, V.; Gorenjak, M. Toward Explainable Time-Series Numerical Association Rule Mining: A Case Study in Smart-Agriculture. Mathematics 2025, 13, 2122. https://doi.org/10.3390/math13132122

[2] Iztok Fister Jr., Dušan Fister, Iztok Fister, Vili Podgorelec, Sancho Salcedo-Sanz. Time series numerical association rule mining variants in smart agriculture. Journal of Ambient Intelligence and Humanized Computing (2023): 1-14.

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

niaarmts-0.2.4.tar.gz (23.3 kB view details)

Uploaded Source

Built Distribution

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

niaarmts-0.2.4-py3-none-any.whl (23.7 kB view details)

Uploaded Python 3

File details

Details for the file niaarmts-0.2.4.tar.gz.

File metadata

  • Download URL: niaarmts-0.2.4.tar.gz
  • Upload date:
  • Size: 23.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.13.7 Linux/6.16.3-200.fc42.x86_64

File hashes

Hashes for niaarmts-0.2.4.tar.gz
Algorithm Hash digest
SHA256 1700e1f7275f4e020ac1eef8179fb7efdbfee9534fd82f247d24f664cbc108ad
MD5 f3acb5524874c9a80cb61b198ead09e0
BLAKE2b-256 94018a6bb5fa06a4e0aeb26b8944bfccd557f4e753af11592f9e002ca3dea424

See more details on using hashes here.

File details

Details for the file niaarmts-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: niaarmts-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 23.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.13.7 Linux/6.16.3-200.fc42.x86_64

File hashes

Hashes for niaarmts-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 342fa52b311dbc4706854bfb1aefffa7390338550be35ca5f07c8d350c7fdc00
MD5 1ce6f73fdcf42cfa560aeebf84d9809a
BLAKE2b-256 b487efeeaf717944090ebd2f1e5578f6968b3842ac8d2e6980861fc2759838e3

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