How to run a regression analysis in python on a nonlinear, strange dataset

I can't figure out what type of regression analysis or extrapolation technique to use in order to come up with an equation for the data I have plotted.

For a school project, I've been testing diodes by connecting them to a temperature switch that shuts off the circuit once the temperature reaches around 250 degrees Celsius. I plotted the data, and I wanted to extrapolate it and get an equation that I could use to predict future diode temperatures. However, I have tried all sorts of extrapolation techniques and none of them accurately fits the data. For example

extrapolation1

as well as this:

extrapolation2

I've tried extrapolation/regressions in both R Studio and python, but I simply cannot get an accurate enough equation for either. Is there anything I could improve in my code, or maybe is there another technique I could use?

This is the code I used to get the first graph:

import numpy as np
import pandas as pd
from scipy.optimize import curve_fit

df = pd.read_csv("JB WELD DIODE REG.csv")
def func(x, a, b, c,d):
return a*np.sin(b*x-c)+d
x = (df.time)/10**2
y= (df.diode)/10**2

popt, pcov = curve_fit(func, x, y)
popt

plt.plot(x, func(x, *popt), 'r-',
label='fit: a=%5.3f, b=%5.3f, c=%5.3f, d=%5.3f' %tuple(popt)
)
plt.plot(x, y)


migrated from stackoverflow.comDec 26 '18 at 7:38

This question came from our site for professional and enthusiast programmers.

• If you post a link to the data file, I can run the data through my Python open source "function finder" at zunzun.com and see what candidate equations it suggests. It has hundreds of known, named equations to search through. – James Phillips Dec 26 '18 at 11:20
• What's on the X axis? Time? – HakunaMaData Dec 26 '18 at 12:55
• Why doesn't the temperature fall all the way to room temperature.. is that because you're not letting the diode cool down? Also, Why did the temperature start from close to zero in the beginning? It is important as you could model this as noise and ignore parts of the curves. – HakunaMaData Dec 26 '18 at 13:02