aggregate_impact_df(impacts_df, agg_levels=None, prepare_for_viz=True, **level_subset)
function for aggregating the impact df at any level
Parameters:
Name | Type | Description | Default |
---|---|---|---|
impacts_df |
DataFrame
|
Dataframe containing impacts from the model |
required |
agg_levels |
list[str] | str | None
|
Hierarchical level(s) to aggregate over. If not specified, full country aggregation is computed. |
None
|
prepare_for_viz |
bool
|
description. Flattens columns in order to visualize. Defaults to True. |
True
|
**level_subset |
dict[str, str | list[str]]
|
all kwargs are used to subset the dataset. For example |
{}
|
Raises:
Type | Description |
---|---|
KeyError
|
error when specified subsets do not exist in the data |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: transformed dataframe after all specified aggregations and subsets |
Source code in wt_ml/tabulation/tabulation_utils.py
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 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
|
get_all_inc_revenues_df(dataset_factory, encodings, gt_model, denormalize=False, total_impact_from_date=False)
Utility function for getting impacts from investments for entire data
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset_factory |
DataFactoryType
|
generator function for iterating over batches of data. |
required |
encodings |
dict
|
mapping from names to indices for wholesalers, brands, products, vehicles and so on. |
required |
gt_model |
EconomicNetwork
|
trained ground truth model to be used for inference. |
required |
denormalize |
bool
|
Denormalize the results or not. Defaults to False. |
False
|
total_impact_from_date |
bool
|
Whether to calculate the total impacts of today's spend alone or to take the impacts of all the spends made until today. Defaults to False. Must for True when calculating ROIs. |
False
|
Returns:
Type | Description |
---|---|
pd.DataFrame: impacts from media or promotional investments for entire data |
Source code in wt_ml/tabulation/tabulation_utils.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
|
get_all_roicurves_df(dataset_factory, encodings, gt_model, levers, denormalize=False)
Utility function for getting diminishing return curves dataframe for entire data
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset_factory |
DataFactoryType
|
generator function for iterating over batches of data. |
required |
encodings |
dict
|
mapping from names to indices for wholesalers, brands, products, vehicles and so on. |
required |
gt_model |
EconomicNetwork
|
trained ground truth model to be used for inference. |
required |
levers |
list
|
list of commerical levers. Can be either all media-vehicles or promo-vehicles currently. |
required |
curve_type |
str
|
Nature of ROICurve. Can be "invest" or "promo". Defaults to "invest". |
required |
denormalize |
bool
|
Denormalize the results or not. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
pd.DataFrame: diminishing return curves dataframe for entire data |
Source code in wt_ml/tabulation/tabulation_utils.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
|
get_entire_impacts_df(dataset_factory, encodings, gt_model, separate_decay=False, merge_granularities=False, total_impact_from_date=False, only_impacts=True, denormalize=False, training=False, collapse_lead_lag=None, apply_sales_mask=True)
Utility function for getting model predicted impacts for entire data
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset_factory |
DataFactoryType
|
generator function for iterating over batches of data. |
required |
encodings |
dict
|
mapping from names to indices for wholesalers, brands, products, vehicles and so on. |
required |
gt_model |
EconomicNetwork
|
trained ground truth model to be used for inference. |
required |
separate_decay |
bool
|
Whether to report separate impact columns for betagamma decay or not. Defaults to False. |
False
|
merge_granularities |
bool
|
Represent the wholesaler,product-packs as a single level or a multi-index. Defaults to False. |
False
|
total_impact_from_date |
bool
|
Whether to use cumulative decay till date or today's decay on future as on today. Defaults to False. |
False
|
only_impacts |
bool
|
Whether to get only model predicted impacts or impacts with epochs and yhat. Defaults to True. |
True
|
denormalize |
bool
|
Denormalize the results or not. Defaults to False. |
False
|
training |
bool
|
If True, query the model in training mode, otherwise not. Defaults to False. |
False
|
Returns: pd.DataFrame: model learnt impacts dataframe on entire data
Source code in wt_ml/tabulation/tabulation_utils.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
|
stack_df_and_rename_col(df, col_name)
Utility function for getting unpivoted view of the dataframe
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
dataframe to unpivot |
required |
col_name |
str
|
name of the column containing values of df |
required |
Returns:
Type | Description |
---|---|
pd.DataFrame: unpivoted view of the dataframe |
Source code in wt_ml/tabulation/tabulation_utils.py
176 177 178 179 180 181 182 183 184 185 186 187 188 |
|