Mine

class niaarm.mine.Result(rules, run_time)

Result of an algorithm run as a namedtuple.

rules

A list of mined association rules.

Type:

RuleList

run_time

The run time of the algorithm in seconds.

Type:

float

niaarm.mine.get_rules(dataset, algorithm, metrics, max_evals=inf, max_iters=inf, logging=False, **kwargs)

Mine association rules on a dataset.

Parameters:
  • dataset (Dataset) – Dataset to mine rules on.

  • algorithm (niapy.algorithms.Algorithm | str) – Algorithm to use. Can be either an Algorithm object or the class name as a string. In that case, algorithm parameters can be passed in as keyword arguments.

  • metrics (dict[str, float] | Sequence[str]) – Metrics to take into account when computing the fitness. Metrics can either be passed as a Dict of pairs {‘metric_name’: <weight>} or a sequence of metrics as strings, in which case, the weights of the metrics will be set to 1.

  • max_evals (int | None) – Maximum number of iterations. Default: inf. At least one of max_evals or max_iters must be provided.

  • max_iters (int | None) – Maximum number of fitness evaluations. Default: inf.

  • logging (bool) – Enable logging of fitness improvements. Default: False.

Returns:

A named tuple containing the list of mined rules and the algorithm’s

run time in seconds.

Return type:

Result

niaarm.mine.get_text_rules(corpus, max_terms, algorithm, metrics, smooth=True, norm=2, threshold=0, max_evals=inf, max_iters=inf, logging=False, **kwargs)

Mine association rules in a text corpus.

Parameters:
  • corpus (Corpus) – Dataset to mine rules on.

  • max_terms (int) – Maximum number of terms in association rule.

  • algorithm (niapy.algorithms.Algorithm | str) – Algorithm to use. Can be either an Algorithm object or the class name as a string. In that case, algorithm parameters can be passed in as keyword arguments.

  • metrics (dict[str, float] | Sequence[str]) – Metrics to take into account when computing the fitness. Metrics can either be passed as a dict of pairs {‘metric_name’: <weight of metric>} or a sequence of metrics as strings, in which case, the weights of the metrics will be set to 1.

  • smooth (bool) – Smooth idf to prevent division by 0 error. Default: True.

  • norm (int) – Order of norm for normalizing the tf-idf matrix. Default: 2.

  • threshold (float | None) – Threshold of tf-idf weights. If a weight is less than or equal to the threshold, the term is not included in the transaction. Default: 0.

  • max_evals (int | None) – Maximum number of iterations. Default: inf. At least one of max_evals or max_iters must be provided.

  • max_iters (int | None) – Maximum number of fitness evaluations. Default: inf.

  • logging (bool) – Enable logging of fitness improvements. Default: False.

Returns:

A named tuple containing the list of mined rules and the algorithm’s run time in seconds.

Return type:

Result