The use of weights is described here (numpy.polyfit) . Basically, you need a weight vector with the same length as x and y.
To avoid the wrong sign in the coefficient, you can use the definition of the fit function, for example
def fitfunc(x,a,b,c): return -1 * abs(a) * x**2 + b * x + c
This will give you a negative coefficient for x ** 2 at any time.
source share