Skip to content

Commit

Permalink
Merge pull request #131 from washingtonpost/error-handling
Browse files Browse the repository at this point in the history
Error handling
  • Loading branch information
jjcherian authored Nov 5, 2024
2 parents b68952a + 6aae2ba commit 7271656
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/elexmodel/handlers/data/VersionedData.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ def compute_estimated_margin(df):
"percent_expected_vote": np.arange(101),
"nearest_observed_vote": np.nan * np.ones(101),
"est_margin": np.nan * np.ones(101),
"est_correction": np.nan * np.ones(101),
"error_type": "non-monotone percent expected vote",
}
)

Expand All @@ -152,6 +154,8 @@ def compute_estimated_margin(df):
"percent_expected_vote": np.arange(101),
"nearest_observed_vote": np.nan * np.ones(101),
"est_margin": np.nan * np.ones(101),
"est_correction": np.nan * np.ones(101),
"error_type": "batch_margin",
}
)

Expand Down Expand Up @@ -196,10 +200,17 @@ def compute_estimated_margin(df):
"nearest_observed_vote": percent_vote[np.clip(obs_indices + 1, 0, len(percent_vote) - 1)],
"est_margin": est_margins,
"est_correction": norm_margin[-1] - est_margins,
"error_type": "none",
}
)

results = results.groupby("geographic_unit_fips").apply(compute_estimated_margin).reset_index()

for error_type in sorted(set(results["error_type"])):
if error_type == "none":
continue
category_error_type = results[results["error_type"] == error_type].geographic_unit_fips.unique()
LOG.info(f"# of versioned units with {error_type} error: {len(category_error_type)}")
return results

def get_versioned_predictions(self, filepath=None):
Expand Down

0 comments on commit 7271656

Please sign in to comment.