2016-10-25 3 views
0

Ich versuche multivariable nichtlineare Regression mit Python zu tun. Stunde, Tag und Zeit sind die unabhängigen Variablen und Last ist die abhängige Variable.Multipolyfit IndexError: Tupel Index außerhalb des Bereichs

Ich habe numpy und multipolyfit installiert.

Der Python-Code ist der folgende:

import numpy, multipolyfit 
data=numpy.loadtxt("midatl_combined.txt") 
hour=data[:,3] 
day=data[:,4] 
temps=data[:,5] 
load=data[:,6] 

a,b,c,d=numpy.polyfit(temps, load, 3) 

a=str(round(a,2)) 
b=str(round(b,2)) 
c=str(round(c,2)) 
d=str(round(d,2)) 

print "load = " +a+" * temp^3 + " +b+" * temp^2 + " +c+" * temp + " +d 

a, b, c, d, e=multipolyfit.multipolyfit(hour, day, temps, load, 3) 

Der Ausgang ist

load = -3.91 * temp^3 + 547.89 * temp^2 + -25367.77 * temp + 416600.52 
Traceback (most recent call last): 
    File "midatl.py", line 84, in <module> 
    a, b, c, d, e=multipolyfit.multipolyfit(hour, day, temps, load, 3) 
    File "c:\Python27\lib\site-packages\multipolyfit-0.0.1- 
py2.7.egg\multipolyfit\ 
core.py", line 54, in multipolyfit 
    num_covariates = xs.shape[1] 
IndexError: tuple index out of range 

Die eine variable Regressions funktioniert gut, aber die multivariable Regressions nicht not.Why bin ich das immer Error?

+0

Vielen Dank, Angus Williams! –

+0

Da gehen Sie, akzeptieren Sie, wenn Sie meine Antwort hilfreich gefunden haben! Danke –

+0

Angus Williams, die Koeffizienten, die ich für einen Grad von 2 bekomme, sind [35605. 1314. 497. -496. -41. -45. 1. -449. 50. 2. ] Weißt du, in welcher Reihenfolge (x^2 y^2 x^1 ...) oder (x^2 x^1 x^0) –

Antwort

0

Sie rufen nicht multipolyfit in der richtigen Weise. Der Docstring schlägt vor, dass es als multipolyfit.multipolyfit(xs,y,deg) verwendet werden soll, wobei xs : array_like, shape (M, k) Ihre hour, day und temps sind. Dies deutet darauf hin, dass sie wie ein einzelnes Array wie folgt übergeben werden müssen:

multipolyfit.multipolyfit(np.vstack((hour,day,temps)).T ,load,3) 
Verwandte Themen