# Find fit function with linear and quadratic component

I would like to find fit functions for data, that has linear dependency first and changes to quadratic at some point.

The fit function should then be used to predict future values. Since I am new to pymc3, I looked into some examples and tried to use them for my problem. The concept of spline regression (https://ckrapu.github.io/2018/07/09/Spline-Regression.html) seemed promising. Here is the notebook with my approach: https://nbviewer.jupyter.org/github/violairis/Spline-Regression-with-pymc3/blob/master/Spline%20Regression%20using%20pymc3.ipynb

But the best result I was able to get looks like this: Could you give me a hint, where I am doing wrong? I would also be happy to hear about alternative approaches to this kind of problem, in case the spline regression is not a good way to handle this. Any help is much apprechiated, thank you!

That data looks like it could be pretty well represented with a standard polynomial regression. Have you tried that?
You probably need a cubic fit here due to that dip around x=1.25.

``````b0 = pm.Normal('b0', 0, sd=10**4)
b1 = pm.Normal('b1', 0, sd=10**4)
b2 = pm.Normal('b2', 0, sd=10**4)
model_error = pm.HalfNormal('error', 10**4)
y_obs ~ pm.Normal('y', mu=b0+b1*np.pow(x,2)+b2*np.pow(x,3), sd=model_error, observed=y)
``````

I just chose relativly flat priors on b0-2, you might want something more informative