Ich möchte die Polynome in einer Liste speichern, aber wenn ich sie in die Liste anfügen verlieren sie die Variable x und haben nur die Koeffizienten.Speichern von Polynomen wie aus der von Poly1D() -Funktion in eine Liste
import numpy as np
from numpy import random
from pylab import *
from sklearn.metrics import r2_score
np.random.seed(2)
pageSpeeds = np.random.normal(3.0, 1.0, 1000)
# purchaseAmount function (non-linear)
purchaseAmount = np.random.normal(50.0, 10.0, 1000)/pageSpeeds
x = np.array(pageSpeeds)
y = np.array(purchaseAmount)
polyfitInit = {1:0, 2:0, 3:0, 4:0, 5:0, 6:0, 7:0, 8:0, 9:0, 10:0, 11:0, 12:0, 13:0, 14:0, 15:0}
polyforms = []
for c in polyfitInit:
z = np.poly1d(np.polyfit(x, y, c))
r2 = r2_score(y, z(x))
polyfitInit[c] = r2
polyforms.append(z)
print polyforms
ouptut jetzt:
[poly1d ([-9,04306562, 46,68709008]), poly1d ([3,73263241, -31,78596189, 77,53159067] ...]
Ausgang gesucht: [-9,043 x + 46.69, 3.73263241x^2 + -31.78596189x + 77,53159067 ...]
Danke Jungs