Created
January 6, 2021 16:57
-
-
Save SuperCipher/1e8f306dd16072262cb6f11ba4670091 to your computer and use it in GitHub Desktop.
Test Thailand coronavirus graph fitting
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
import numpy as np | |
from scipy.optimize import curve_fit | |
import matplotlib.pyplot as plt | |
# %matplotlib inline | |
x = [46,67,81,110,121,144,155,250,194,279,216,315,745,527] | |
j = 0 | |
buckets = [0] * len(x) | |
m = 0 | |
for i in x: | |
m += i | |
buckets[j] = m | |
j += 1 | |
buckets | |
y = list(range(1, len(x)+1)) | |
# plt.plot( y,x) | |
# plt.plot( y,buckets) | |
# def exponential(x, a, b): | |
# return a*np.exp(b*x) | |
x = np.array(y) | |
y = np.array(buckets) | |
# Function to calculate the exponential with constants a and b | |
def func(x, a, b): | |
return a * np.exp(b * x) | |
params, param_cov = curve_fit(func, x, y) | |
print(params) | |
print(param_cov) | |
ans = (params[0]*(np.exp(params[1]*x))) | |
plt.plot(x, y, 'o', color ='red', label ="data") | |
plt.plot(x, ans, '--', color ='blue', label ="optimized data") | |
plt.legend() | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://colab.research.google.com/drive/1k4CfYsIwoAOAHnd_a15tFbm6AyxojiCx