I'm working on two functions. I have two data sets, eg [[x(1), y(1)], ..., [x(n), y(n)]]
, dataSet
and testData
.
createMatrix(D, S)
which returns a data matrix, where D
is the degree and S
is a vector of real numbers [s(1), s(2), ..., s(n)]
.
I know numpy
has a function called polyfit
. But polyfit
takes in three variables, any advice on how I'd create the matrix?
polyFit(D)
, which takes in the polynomial of degree D
and fits it to the data sets using linear least squares. I'm trying to return the weight vector and errors. I also know that there is lstsq
in numpy.linag
that I found in this question: Fitting polynomials to data
Is it possible to use that question to recreate what I'm trying?
This is what I have so far, but it isn't working.
def createMatrix(D, S):
x = []
y = []
for i in dataSet:
x.append(i[0])
y.append(i[1])
polyfit(x, y, D)
What I don't get here is what does S, the vector of real numbers, have to do with this?
def polyFit(D)
I'm basing a lot of this on the question posted above. I'm unsure about how to get just w
though, the weight vector. I'll be coding the errors, so that's fine I was just wondering if you have any advice on getting the weight vectors themselves.