-1

I have a dataset Coronavirus cases per day with dates And then I made this plot, Cases vs Days, which is a curved line. Graph

I would like to fit a curved line that predicts future cases. But how to do that? I'm new and I'm used to linear regression. Fitting a linear regression line is much simpler. Is there any simple way to fit a curved line too? I tried youtube but there aren't many videos on this. And how can I print predicted cases for the next 10 days? Thank you very much.

Community
  • 1
  • 1
mikal
  • 55
  • 6
  • Can you post code from what you've tried already? –  Apr 08 '20 at 18:00
  • @SilverNitrateIon I only preprocessed the dataset. I haven't tried any code yet. I saw the sklearn svr documentation. But couldn't understand the syntax. I thought there might be an easier way to do this. – mikal Apr 08 '20 at 18:04
  • You can try a gaussian process regression https://scikit-learn.org/stable/modules/gaussian_process.html, though looking at the newer comments it may not be any simpler syntax than SVR. – M-Wi Apr 08 '20 at 18:05

1 Answers1

2

If you are looking to fit higher order polynomials, you are typically looking either for spline fitting or polyfit. Spline fitting will draw a fit using a specified number of line segments, where as polyfit will fit a polynomial of specified order to the system given.

Example from the docs for spline fitting:

x = np.linspace(0, 10, num=11, endpoint=True)
y = np.cos(-x**2/9.0)
f = interp1d(x, y)

From the docs for polyfit

x = np.array([0.0, 1.0, 2.0, 3.0,  4.0,  5.0])
y = np.array([0.0, 0.8, 0.9, 0.1, -0.8, -1.0])
z = np.polyfit(x, y, 3)

Polyfit has the advantage of allowing you to extrapolate rather easily by calling the generated polyfit function on the value, whereas spline fits require more advanced extrapolation methods, as per this post here.

  • 1
    @ALollz I completely agree, you would want to use something like a SIR model (for instance), however, the poster asked for poly-fitting/curve fitting measures. –  Apr 08 '20 at 18:27