Metrics¶
- niaarmts.metrics.calculate_amplitude_metric(features, antecedents, consequents)¶
Calculate the amplitude metric for the given rule, based on the ranges of numerical attributes in the antecedents and consequents. The amplitude metric rewards smaller ranges, indicating tighter intervals for numerical conditions.
- Parameters:
features (dict) – A dictionary of feature metadata for the dataset.
antecedents (list) – A list of dictionaries defining the antecedent conditions.
consequents (list) – A list of dictionaries defining the consequent conditions.
- Returns:
The amplitude metric value, normalized between 0 and 1. A higher value indicates tighter numerical ranges in the antecedents and consequents.
- Return type:
float
- niaarmts.metrics.calculate_confidence(df, antecedents, consequents, start, end, use_interval=False)¶
Calculate the confidence for the given list of antecedents and consequents within the specified time range or interval range.
- Parameters:
df (pd.DataFrame) – The dataset containing the transactions.
antecedents (list) – A list of dictionaries defining the antecedent conditions.
consequents (list) – A list of dictionaries defining the consequent conditions.
start (int or datetime) – The start of the interval (if use_interval is True) or timestamp range.
end (int or datetime) – The end of the interval (if use_interval is True) or timestamp range.
use_interval (bool) – Whether to filter by ‘interval’ (True) or ‘timestamp’ (False) for time-based filtering.
- Returns:
The confidence value, which is the ratio of rows matching both antecedents and consequents to the rows matching antecedents. If no antecedent-matching rows exist, returns 0.
- Return type:
float
- niaarmts.metrics.calculate_fitness(supp, conf, incl, alpha=1.0, beta=1.0, delta=1.0)¶
Calculate the fitness score of a rule using the weighted sum of support, confidence, and inclusion.
The fitness function is used to evaluate how good a particular rule is, based on its support, confidence, and inclusion metrics. The function allows weighting of each metric through the alpha, beta, and delta parameters.
- Parameters:
supp (float) – The support value of the rule.
conf (float) – The confidence value of the rule.
incl (float) – The inclusion value of the rule.
alpha (float) – Weight for the support metric.
beta (float) – Weight for the confidence metric.
delta (float) – Weight for the inclusion metric.
- Returns:
The fitness score, normalized between 0 and 1.
- Return type:
float
- niaarmts.metrics.calculate_inclusion_metric(features, antecedents, consequents)¶
Calculate the inclusion metric, which measures how many attributes appear in both the antecedent and consequent relative to the total number of features in the dataset.
- Parameters:
features (dict) – A dictionary of feature metadata for the dataset.
antecedents (list) – A list of dictionaries defining the antecedent conditions.
consequents (list) – A list of dictionaries defining the consequent conditions.
- Returns:
The inclusion metric value, normalized between 0 and 1.
- Return type:
float
- niaarmts.metrics.calculate_support(df, antecedents, consequents, start=0, end=0, use_interval=False)¶
Calculate the support for the given list of antecedents and consequents within the specified time range or interval range.
- Parameters:
df (pd.DataFrame) – The dataset containing the transactions.
antecedents (list) – A list of dictionaries defining the antecedent conditions.
consequents (list) – A list of dictionaries defining the consequent conditions.
start (int or datetime) – The start of the interval (if use_interval is True) or timestamp range.
end (int or datetime) – The end of the interval (if use_interval is True) or timestamp range.
use_interval (bool) – Whether to filter by ‘interval’ (True) or ‘timestamp’ (False) for time-based filtering.
- Returns:
The support value, which is the ratio of transactions matching both antecedents and consequents to the total transactions in the filtered range. If no transactions exist, returns 0.
- Return type:
float