Open dmnapolitano opened 1 month ago
If we include this, one thing we will definitely want is to make the 4.75 flexible. Any chance you can make that a parameter?
Also curious what happens when a state has no units in or if there is only one unit in so no standard deviation can be computed? Also would be super interested to see how you evaluated this.
So, if there are no units in the state, that probably means those units haven't reported yet or they're all unexpected (hope not), and so they shouldn't ever reach the outlier (or even current turnout factor threshold) detection. If there's only one unit, pandas
returns nan
:
In [1]: import pandas
In [2]: df = pandas.DataFrame([{"foo" : "a", "bar" : 2}, {"foo" : "b", "bar" : 2}, {"foo" : "a", "bar" : 3}, {"foo" : "a", "bar" : 1}])
In [3]: df
Out[3]:
foo bar
0 a 2
1 b 2
2 a 3
3 a 1
In [4]: df.groupby(["foo"]).agg({"bar" : ["mean", "std"]})
Out[4]:
bar
mean std
foo
a 2.0 1.0
b 2.0 NaN
But, I think what we want to happen there is to make sure the unit doesn't get dropped; I don't think it will, the way the code is currently written, but I'll make sure of that 👍🏻 👍🏻
The evaluation is here; LMK what you think and if I should do anything else here 🤔 😄 (It might also be helpful for me to swap in some of the other sets of test bed output I generated to do this, but they were worse 😅 )
If we include this, one thing we will definitely want is to make the 4.75 flexible. Any chance you can make that a parameter?
Done!! See the examples in the "Test Steps" 😄 🎉
Also curious what happens when a state has no units in or if there is only one unit in so no standard deviation can be computed? Also would be super interested to see how you evaluated this.
So, if there are no units in the state, that probably means those units haven't reported yet or they're all unexpected (hope not), and so they shouldn't ever reach the outlier (or even current turnout factor threshold) detection. If there's only one unit,
pandas
returnsnan
:In [1]: import pandas In [2]: df = pandas.DataFrame([{"foo" : "a", "bar" : 2}, {"foo" : "b", "bar" : 2}, {"foo" : "a", "bar" : 3}, {"foo" : "a", "bar" : 1}]) In [3]: df Out[3]: foo bar 0 a 2 1 b 2 2 a 3 3 a 1 In [4]: df.groupby(["foo"]).agg({"bar" : ["mean", "std"]}) Out[4]: bar mean std foo a 2.0 1.0 b 2.0 NaN
But, I think what we want to happen there is to make sure the unit doesn't get dropped; I don't think it will, the way the code is currently written, but I'll make sure of that 👍🏻 👍🏻
The evaluation is here; LMK what you think and if I should do anything else here 🤔 😄 (It might also be helpful for me to swap in some of the other sets of test bed output I generated to do this, but they were worse 😅 )
Alright I confirmed using 2020-11-03_USA_G
and --office_code=P
that DC, which only has one unit in this data set, doesn't get dropped during outlier detection 🎉
Description
Hi! The changes in this PR remove the
turnout_factor_lower
andturnout_factor_upper
thresholds in favor of outlier detection. The mean and standard deviation ofturnout_factor
is determined per state then used to identify outliers via the mean ± (standard deviation * 4.75). This defaultz
threshold has been selected so as to minimize the changes to the unit test results, race call times, and predictions. See the notebook here for more details on performance evaluation against the 2022 US Senate GE 🎉 Thanks!!Jira Ticket
ELEX-3298
Test Steps
tox
,elexmodel
commands with non-modeled units, test bed, etc. For instance:Which uses the default turnout factor z threshold of 4.75. Compared to: