qjhong.github.io's People
Forkers
stan-2204qjhong.github.io's Issues
Correct for changing testing volume by using data from rt.live
I really like your idea, but I thought one thing that could be improved was getting data that corrects for changing testing volume. The site www.rt.live provides this, and the code below, specifically get_dates_positives_totals_and_deaths_rt_live(), can be simply substituted for get_DNC(). The new predictions are similar, but slightly lower, and the regression is nicer.
Also,
- Thank you for sharing your code!
- You might want to refactor it a bit and perhaps upgrade to Python 3 as well. It was difficult to work with.
- Thanks again, and hopefully this is helpful.
-Mike
import csv
tmp = sys.argv
try:
state = tmp[1]
except IndexError:
state = "FL"
print 'Entering debug mode with state' + state
def date_to_datetime(my_date):
if isinstance(my_date, (str,)):
my_date = int(my_date.replace('-',''))
if isinstance(my_date, (int,)) :
return datetime(int(my_date/10000), int(my_date/100) % 100, int(my_date) % 100)
else:
raise NotImplementedError
def rt_live_str_to_float(my_str):
if my_str == '':
return 0.0
else:
return float(my_str)
def get_dates_positives_totals_and_deaths_rt_live(my_state, max_days=99,
num_days_to_use_for_aligning_positive_adjusted=7):
# Download data from rt.live, which corrects cases for testing volume
with requests.Session() as s:
download = s.get('https://d14wlfuexuxgcm.cloudfront.net/covid/rt.csv')
decoded_content = download.content.decode('utf-8')
rt_live_csv_reader = csv.reader(decoded_content.splitlines(), delimiter=',')
rt_live_rows = list(rt_live_csv_reader)
my_state_index = rt_live_rows[0].index('region')
my_date_index = rt_live_rows[0].index('date')
my_positive_index = rt_live_rows[0].index('positive_test_adjusted_raw')
my_positive_no_adjustment_index = rt_live_rows[0].index('positive')
my_test_index = rt_live_rows[0].index('new_tests')
my_death_index = rt_live_rows[0].index('new_deaths')
my_dates = list()
my_positives = list()
my_totals = list()
my_deaths = list()
my_positive_no_adjustment = list()
rt_live_rows_sorted_body = rt_live_rows.copy()
rt_live_rows_sorted_body = rt_live_rows_sorted_body[1:]
rt_live_rows_sorted_body.sort()
for rt_live_row in rt_live_rows_sorted_body: #Make sure to skip the header row.
this_date = date_to_datetime(rt_live_row[my_date_index])
if rt_live_row[my_state_index] == my_state or (my_state == "US" and this_date not in my_dates):
my_dates.append(this_date)
my_positives.append(rt_live_str_to_float(rt_live_row[my_positive_index]))
my_positive_no_adjustment.append(rt_live_str_to_float(rt_live_row[my_positive_no_adjustment_index]))
my_deaths.append(rt_live_str_to_float(rt_live_row[my_death_index]))
my_totals.append(rt_live_str_to_float(rt_live_row[my_test_index]))
#TODO: fix this
elif my_state == "US": # And we haven't seen this date before
my_index = my_dates.index(this_date)
my_positives[my_index] += rt_live_str_to_float(rt_live_row[my_positive_index])
my_positive_no_adjustment[my_index] += rt_live_str_to_float(rt_live_row[my_positive_no_adjustment_index])
my_deaths[my_index] += rt_live_str_to_float(rt_live_row[my_death_index])
my_totals[my_index] += rt_live_str_to_float(rt_live_row[my_test_index])
my_cumulative_deaths = [0.0] * len(my_deaths)
for my_cd_i, daily_new_deaths in enumerate(my_deaths):
my_cumulative_deaths[my_cd_i] = my_cumulative_deaths[max(my_cd_i - 1, 0)] + daily_new_deaths
for my_list in my_dates, my_positives, my_totals, my_cumulative_deaths, my_positive_no_adjustment:
my_list.reverse()
num_to_pop = max(0, len(my_list) - max_days)
for popper in range(num_to_pop):
my_list.pop()
# Align most recent x days
positives_total = 0
positives_no_adjustment_total = 0
for jj in range(num_days_to_use_for_aligning_positive_adjusted):
positives_total += my_positives[jj]
positives_no_adjustment_total += my_positive_no_adjustment[jj]
factor_to_multiply_adjusted_positives_so_they_approximate_tested_positives = positives_no_adjustment_total / positives_total
adjusted_positives = [int(x * factor_to_multiply_adjusted_positives_so_they_approximate_tested_positives) for x in my_positives]
adjusted_totals = [int(x * factor_to_multiply_adjusted_positives_so_they_approximate_tested_positives) for x in my_totals]
return my_dates, adjusted_positives, adjusted_totals, my_cumulative_deaths```
Output data in correct format and submit to forcast hub.
It would help your model get more views if you output the data in the following format and submit to the github project below, which serves as a central location for many forecasts, as well as a well of comparing model performance in a standard way and also powering a larger ensemble model.
https://github.com/reichlab/covid19-forecast-hub#forecast-file-format
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.