I have a quite sophisticated problem (for me). I have written a code that calculates interpolation for a given data set. After that it calculates the Akaike information criterium to check which interpolation suite best.
Looks like that:
polyfit=np.polyfit(x,y,5) # x,y are data set and 5 is a root of polynomial
poly1d=np.poly1d(polyfit)
print poly1d #show final polynomial
my=[]
for i in x:
x_=poly1d(i)
my.append(x_) #calculate list of values
def AIC(i,j):
for i in y:
for j in my:
RSS=(i-j)**2
AIC=36-np.log(RSS)
print AIC
And I don't like this code because if I want to change root of polynomial I have to change the code. I know that I have to use for loop in the beginning like:
for i in xrange(40):
polyfit=np.polyfit(x,y,i)
but I can't figure out how to save all of my polynomials to a list. If I knew that I would use it to calculate def AIC() for any root, and then I could find the best curve fit for my data. Please help guys, it has been bothering me for 2 weeks already. If there is anything not clear to you, please ask.