Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Need helping using curve_fit on python to find optimal values for alpha and beta In [1]: from scipy.optimize import curve_fit from sklearn.metrics import mean_squared_error import
Need helping using curve_fit on python to find optimal values for alpha and beta
In [1]: from scipy.optimize import curve_fit from sklearn.metrics import mean_squared_error import numpy as np from scipy.integrate import odeint import matplotlib.pyplot as plt In [7]: infected = np.array([ 25, 75, 227, 296, 258, 236, 192, 126, 71, 28, 11, 7]) days = np.array([3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) alpha = 0.3 beta = 0.0025 y0 = 738, 25, 2 def model(y, t, alpha, beta): S, I, R = y dsdt = -beta * I * S dIdt = beta * I * S - alpha * I dRdt = alpha * I return dsdt, didt, dRdt pend = odeint(func=model, y0 = (738, 25, 2), t=days, args=(alpha, beta)) S, I, R = pend.T In [9]: guess = (alpha, beta] c, cov = curve_fit(model, days, infected, guess [0], guess[1]) print(c) ValueError Traceback (most recent call last) ipython-input be4 2ca5> inStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started