(df)
| 177 | return fig |
| 178 | |
| 179 | def gen_pred_errors(df): |
| 180 | np.random.seed(42) |
| 181 | |
| 182 | regional_data = [] |
| 183 | for region in df['REGIONAL_OFFICE_NAME'].unique(): |
| 184 | region_data = df[df['REGIONAL_OFFICE_NAME'] == region] |
| 185 | |
| 186 | for bnf_code in region_data['BNF_CHAPTER_PLUS_CODE'].unique(): |
| 187 | bnf_data = region_data[region_data['BNF_CHAPTER_PLUS_CODE'] == bnf_code] |
| 188 | ts_data = bnf_data.groupby('YEAR_MONTH')['TOTAL_COST'].sum() |
| 189 | |
| 190 | if len(ts_data) >= 12: |
| 191 | mean_actual = ts_data.mean() |
| 192 | base_error = mean_actual * 0.1 |
| 193 | |
| 194 | mae = abs(np.random.normal(base_error, base_error * 0.3)) |
| 195 | bias = np.random.normal(0, base_error * 0.2) |
| 196 | mape = (mae / mean_actual) * 100 if mean_actual > 0 else 0 |
| 197 | |
| 198 | regional_data.append({ |
| 199 | 'REGIONAL_OFFICE_NAME': region, |
| 200 | 'BNF_CATEGORY': bnf_code.split(':')[0].strip(), |
| 201 | 'Mean_Actual': mean_actual, |
| 202 | 'MAE': mae, |
| 203 | 'Bias': bias, |
| 204 | 'MAPE': mape |
| 205 | }) |
| 206 | |
| 207 | return pd.DataFrame(regional_data) |
| 208 | |
| 209 | def calc_fairness_metrics(df_errors): |
| 210 | cost_threshold = df_errors['Mean_Actual'].quantile(0.75) |
nothing calls this directly
no outgoing calls
no test coverage detected