Skip to content

Instantly share code, notes, and snippets.

@samnissen
Created March 9, 2020 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samnissen/46493ee7aebe61d234f1e35d8d67dab5 to your computer and use it in GitHub Desktop.
Save samnissen/46493ee7aebe61d234f1e35d8d67dab5 to your computer and use it in GitHub Desktop.
Predict the number of new COVID-19 cases tomorrow
day new total
1 0 0
2 0 0
3 0 0
4 0 0
5 0 0
6 0 0
7 0 0
8 2 2
9 0 2
10 0 2
11 0 2
12 0 2
13 1 3
14 0 3
15 1 4
16 4 8
17 0 8
18 1 9
19 0 9
20 0 9
21 0 9
22 0 9
23 0 9
24 0 9
25 0 9
26 0 9
27 4 13
28 0 13
29 0 13
30 2 15
31 5 20
32 3 23
33 11 34
34 4 38
35 11 49
36 36 85
37 29 114
38 47 161
39 43 204
40 66 270
41 46 316
require 'csv'
require 'eps'
# Data for the UK
# Read from here, and definitely rough:
# https://www.bbc.co.uk/news/world-51235105
#
# An example snippet:
# ---------------------
# | day | new | total |
# ---------------------
# | 14 | 0 | 0 |
# | 15 | 1 | 1 |
# | 16 | 4 | 5 |
# | 17 | 0 | 5 |
# | 18 | 1 | 6 |
# ---------------------
FILE_PATH = ENV['C19_FILE_PATH']
text = File.read(FILE_PATH)
csv = CSV.parse(text, headers: true)
rows = csv.map do |raw|
raw.to_hash.inject({}){|memo,(k,v)| memo[k.to_sym] = v.to_i; memo}
end # https://stackoverflow.com/a/800498/1651458
model = Eps::Model.new(rows, target: :new)
modifier = (rows.last[:day] + 1)
payload = {day: modifier, total: rows.last[:total]}
# I don't know why you have to add the total, but you do.
# Changing it seems to do nothing thus far.
puts "\n"
puts "Making a prediction for day #{payload[:day]}"
puts "Prediction: #{model.predict(payload)}"
puts "\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment