1

I am using the function Multipolyfit to create a 2nd degree function with 3 independent variables (trivariate quadratic). The code is the following

data=numpy.loadtxt("file.txt")
hour=data[:,3]
day=data[:,4]
temp=data[:,5]
load=data[:,6]
a=multipolyfit.multipolyfit(numpy.vstack((hour,day,temp)).T, load, 2)
print a

Day, temp, and load are the independent variables. Load is the variable I am trying to predict. The output seems to be the list of the 8 coefficients for my trivariate quadratic.

[ 27011.    771.   5462.   -394.    -29.    -83.     10.   -804.      9.      1]

What order are the above coefficients in?

1 Answers1

0

Multipolyfit is poorly documented. The author even mentions the following in their github readme file:

I rarely respond to questions about this repository. It is oddly popular but the implementation is pretty dense and so this project generates a large number of reasonable questions. Unfortunately I don't have time to respond to all of these.

I would care more about this project if it contained a useful algorithm. It doesn't.

Luckily for us, the code in its entirety is less than a hundred lines and pretty easy to navigate through. It creates permutations of the coefficient powers as:

[[2 0 0 0]
 [1 1 0 0]
 [1 0 1 0]
 [1 0 0 1]
 [0 2 0 0]
 [0 1 1 0]
 [0 1 0 1]
 [0 0 2 0]
 [0 0 1 1]
 [0 0 0 2]]

where the columns correspond to the power of [1,hour,day,temp], respectively. So for your coefficients, you get 27011*(1**2) + 771*(1**1 * hour**1) + .... You can get this yourself without digging through the code by setting the keyword argument powers_out=True:

>>> a,powers=multipolyfit.multipolyfit(numpy.vstack((hour,day,temp)).T,
                                       load, 2, powers_out=True)
[array([2, 0, 0, 0]), array([1, 1, 0, 0]), array([1, 0, 1, 0]), array([1, 0, 0, 1]), array([0, 2, 0, 0]), array([0, 1, 1, 0]), array([0, 1, 0, 1]), array([0, 0, 2, 0]), array([0, 0, 1, 1]), array([0, 0, 0, 2])]
Brian
  • 1,988
  • 1
  • 14
  • 29