Created
February 6, 2020 15:52
-
-
Save CyrusF/686ef252a7efef7066ce13c5d1995fbb to your computer and use it in GitHub Desktop.
nCov poly-fitting prediction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| a = [41,4,17,59,78,92,149,131,259,444,688,769,1771,1459,1737,1982,2102,2590,2829,3235,3887,3694] | |
| after_days = 6 | |
| b = [sum(a[0:i+1]) for i in range(after_days, len(a))] | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| x = [i for i in range(after_days, len(a))] | |
| x = np.array(x) | |
| print('x =',x) | |
| y = np.array(b) | |
| print('y =',y) | |
| f1 = np.polyfit(x, y, 2) | |
| p1 = np.poly1d(f1) | |
| print('f(x) =', p1) | |
| yvals = p1(x) | |
| #print('fitvalue =',yvals) | |
| from sklearn.metrics import r2_score | |
| print('r square=', r2_score(y, yvals)) | |
| print("="*32) | |
| for i in range(6, 29): | |
| print("2月%d日确诊预测\t%d"%(i, int(p1(16+i)))) | |
| plot1 = plt.plot(x, y, 's',label='original values') | |
| plot2 = plt.plot(x, yvals, 'r',label='polyfit values') | |
| plt.xlabel('x') | |
| plt.ylabel('y') | |
| plt.legend(loc=4) | |
| plt.title('polyfitting') | |
| plt.show() | |
| #x = [ 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21] | |
| #y = [ 440 571 830 1274 1962 2731 4502 5961 7698 9680 11782 14372 | |
| # 17201 20436 24323 28017] | |
| #f(x) = 2 | |
| #134.9 x - 1833 x + 6773 | |
| #r square= 0.9995155940673051 | |
| #================================ | |
| #2月6日确诊预测 31752 | |
| #2月7日确诊预测 35991 | |
| #2月8日确诊预测 40500 | |
| #2月9日确诊预测 45278 | |
| #2月10日确诊预测 50326 | |
| #2月11日确诊预测 55644 | |
| #2月12日确诊预测 61232 | |
| #2月13日确诊预测 67090 | |
| #2月14日确诊预测 73218 | |
| #2月15日确诊预测 79615 | |
| #2月16日确诊预测 86283 | |
| #2月17日确诊预测 93220 | |
| #2月18日确诊预测 100427 | |
| #2月19日确诊预测 107904 | |
| #2月20日确诊预测 115650 | |
| #2月21日确诊预测 123667 | |
| #2月22日确诊预测 131953 | |
| #2月23日确诊预测 140510 | |
| #2月24日确诊预测 149336 | |
| #2月25日确诊预测 158432 | |
| #2月26日确诊预测 167798 | |
| #2月27日确诊预测 177433 | |
| #2月28日确诊预测 187339 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment