Skip to content

Instantly share code, notes, and snippets.

@HenkPoley
Last active February 6, 2020 20:37
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 HenkPoley/0efe9d17187730217158de6901f93140 to your computer and use it in GitHub Desktop.
Save HenkPoley/0efe9d17187730217158de6901f93140 to your computer and use it in GitHub Desktop.
2019-nCoV prediction
#!/usr/bin/env python
# Not meant to teach proper Python, or statistics, but it works
import warnings
import numpy
import scipy.stats
x = numpy.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0])
y = numpy.array([4515.0, 5974.0, 7711.0, 9692.0, 11791.0, 14380.0, 17205.0, 20438.0, 24324.0, 28018.0])
z = numpy.polyfit(x,y,2)
print("ax^2 + bx + c: " + str(z[0]) + " * x^2 + "+ str(z[1]) + " * x + " + str(z[2]))
p = numpy.poly1d(z)
# p(1)
# p(2)
predictions = numpy.array([p(1), p(2), p(3), p(4), p(5), p(6), p(7), p(8), p(9), p(10)])
slope, intercept, r_value, p_value, std_err = regres_result = scipy.stats.linregress(y, predictions)
print(regres_result)
# Nonsense
# adjusted_r_squared = (1-(1-r_value) * ((10-1)/(10-3-1)))
# print("Adjusted R squared: " + str(adjusted_r_squared))
# print("Remaining unexplained variance: " + str((1 - adjusted_r_squared) * 100) + "%")
print("")
print("Predictions:")
print("Feb 7: " + str(p(11)))
print("Feb 8: " + str(p(12)))
print("Feb 9: " + str(p(13)))
@HenkPoley
Copy link
Author

HenkPoley commented Feb 6, 2020

Current output of this script:

ax^2 + bx + c: 160.113636364 * x^2 + 837.174242424 * x + 3635.96666667
LinregressResult(slope=0.99977799747621676, intercept=3.1979019545997289, rvalue=0.99988899257678443, pvalue=6.6424499499822616e-16, stderr=0.0052672720484915241)
Adjusted R squared: 0.999888992577
Remaining unexplained variance: 0.0111007423216%

Predictions:
Feb 7: 32218.6333333
Feb 8: 36738.4212121
Feb 9: 41578.4363636

@HenkPoley
Copy link
Author

HenkPoley commented Feb 6, 2020

Made the script because of these tweets: https://twitter.com/evdefender/status/1225408294585393153

Just from playing with my script a bit, I don't think these statistical methods are appropriate for this limited dataset.

Easy to make a higher order polyfit with an R^2 that approaches 1, and super low p values, but get silly predictions.

But, ehh, I had limited stats edu.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment