Scipy.Odr multiple variable Regression
Ich möchte eine mehrdimensionale ODR mit @ durchführscipy.odr
. Ich habe die API-Dokumentation gelesen, in der steht, dass Mehrdimensionalität möglich ist, aber ich kann nicht dafür sorgen, dass es funktioniert. Ich kann kein funktionierendes Beispiel im Internet finden und die API ist wirklich grob und gibt keine Hinweise, wie ich vorgehen soll.
Hier ist meine MWE:
import numpy as np
import scipy.odr
def linfit(beta, x):
return beta[0]*x[:,0] + beta[1]*x[:,1] + beta[2]
n = 1000
t = np.linspace(0, 1, n)
x = np.full((n, 2), float('nan'))
x[:,0] = 2.5*np.sin(2*np.pi*6*t)+4
x[:,1] = 0.5*np.sin(2*np.pi*7*t + np.pi/3)+2
e = 0.25*np.random.randn(n)
y = 3*x[:,0] + 4*x[:,1] + 5 + e
print(x.shape)
print(y.shape)
linmod = scipy.odr.Model(linfit)
data = scipy.odr.Data(x, y)
odrfit = scipy.odr.ODR(data, linmod, beta0=[1., 1., 1.])
odrres = odrfit.run()
odrres.pprint()
It löst die folgende Ausnahme aus:
scipy.odr.odrpack.odr_error: number of observations do not match
Was mit meinen Matrixformen zu tun zu haben scheint, aber ich weiß nicht, wie ich es richtig formen muss. Weiß jemand