Aggregation Strategies
Module for aggregation strategies.
Author: Daniel Wertheimer
AggregationStrategy
Bases: ABC
Abstract base class for aggregation strategies.
Subclasses should implement the aggregate method to perform a specific type of aggregation.
Methods:
| Name | Description |
|---|---|
aggregate |
Abstract method to be overridden by subclasses to perform aggregation. |
include_col_name |
Indicates whether to include the column name in the output. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the method is not overridden by a subclass. |
Source code in amee_utils/feature_generator/feature_set/aggregation_strategy.py
aggregate(df, agg_col, key_cols)
abstractmethod
Perform aggregation on the specified column and group by the key columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The input DataFrame containing the data to be aggregated. |
required |
agg_col
|
str
|
The column in the DataFrame to be aggregated. |
required |
key_cols
|
List[str]
|
The columns in the DataFrame to group by. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
A DataFrame containing the aggregated data. |
Source code in amee_utils/feature_generator/feature_set/aggregation_strategy.py
include_col_name()
Indicate whether to include the column name in the output.
Returns:
| Type | Description |
|---|---|
bool
|
True if the column name should be included, False otherwise. |
Source code in amee_utils/feature_generator/feature_set/aggregation_strategy.py
CountAggregation
Bases: AggregationStrategy
CountAggregation class for counting occurrences of values in a specified column.
Attributes:
| Name | Type | Description |
|---|---|---|
include_missing |
bool
|
If True, missing values (nulls and NaNs) are included in the count aggregation. If False, missing values are excluded from the count. |
Methods:
| Name | Description |
|---|---|
aggregate |
Aggregate data by counting occurrences. |
_check_contains_missing |
Checks if the specified column contains any missing values (nulls or NaNs). |
Source code in amee_utils/feature_generator/feature_set/aggregation_strategy.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | |
aggregate(df, agg_col, key_cols)
Aggregate data by counting occurrences.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The input DataFrame containing the data to be aggregated. |
required |
agg_col
|
str
|
The column in the DataFrame to be aggregated. |
required |
key_cols
|
List[str]
|
The columns in the DataFrame to group by. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
A DataFrame containing the aggregated data. |
Source code in amee_utils/feature_generator/feature_set/aggregation_strategy.py
CountIfOneAggregation
Bases: AggregationStrategy
CountIfOneAggregation class for counting the number of values that are equal to one.
Methods:
| Name | Description |
|---|---|
aggregate |
Aggregate data by counting occurrences of the number 1. |
Source code in amee_utils/feature_generator/feature_set/aggregation_strategy.py
aggregate(df, agg_col, key_cols)
Aggregate data by counting occurrences of the number 1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The input DataFrame containing the data to be aggregated. |
required |
agg_col
|
str
|
The column in the DataFrame to be aggregated. |
required |
key_cols
|
List[str]
|
The columns in the DataFrame to group by. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
A DataFrame containing the aggregated data. |
Source code in amee_utils/feature_generator/feature_set/aggregation_strategy.py
MeanAggregation
Bases: AggregationStrategy
MeanAggregation class for calculating the mean of values in a specified column.
Methods:
| Name | Description |
|---|---|
aggregate |
Aggregate data by calculating the mean. |
Source code in amee_utils/feature_generator/feature_set/aggregation_strategy.py
aggregate(df, agg_col, key_cols)
Aggregate data by calculating the mean.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The input DataFrame containing the data to be aggregated. |
required |
agg_col
|
str
|
The column in the DataFrame to be aggregated. |
required |
key_cols
|
List[str]
|
The columns in the DataFrame to group by. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
A DataFrame containing the aggregated data. |
Source code in amee_utils/feature_generator/feature_set/aggregation_strategy.py
StddevAggregation
Bases: AggregationStrategy
StddevAggregation class for calculating the standard deviation of values in a specified column.
Methods:
| Name | Description |
|---|---|
aggregate |
Aggregate data by calculating the standard deviation. |
Source code in amee_utils/feature_generator/feature_set/aggregation_strategy.py
aggregate(df, agg_col, key_cols)
Aggregate data by calculating the standard deviation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The input DataFrame containing the data to be aggregated. |
required |
agg_col
|
str
|
The column in the DataFrame to be aggregated. |
required |
key_cols
|
List[str]
|
The columns in the DataFrame to group by. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
A DataFrame containing the aggregated data. |
Source code in amee_utils/feature_generator/feature_set/aggregation_strategy.py
SumAggregation
Bases: AggregationStrategy
SumAggregation class for summing values in a specified column.
Methods:
| Name | Description |
|---|---|
aggregate |
Aggregate data by summing the values. |
Source code in amee_utils/feature_generator/feature_set/aggregation_strategy.py
aggregate(df, agg_col, key_cols)
Aggregate data by summing the values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The input DataFrame containing the data to be aggregated. |
required |
agg_col
|
str
|
The column in the DataFrame to be aggregated. |
required |
key_cols
|
List[str]
|
The columns in the DataFrame to group by. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
A DataFrame containing the aggregated data. |