Can I use a least squares polynomial fit on residuals to estimate variance? Given some residuals, is there any problems with using a least squares polynomial fit to estimate the variance?

The resulting fit looks like this using numpy.polyfit
import numpy as np

poly = np.polyfit(df.VALUES, df.SQ_RESIDUAL, 2)
plt.scatter(df.TOTAL, np.sqrt(np.polyval(poly, df.VALUES)), label='fit')


My goal is to ultimately generate random numbers using the expected value and the estimated variance.
Is there a better way to go about this?

I would probably bootstrap the residuals as an alternative to a poly-fit.
but ....

*

*Small samples are not great for bootstrap so maybe try an alternative.


*you can fit a polynomial to the histogram, but it is probably better to make a parameterized distributional assumption
Why not fit a normal distribution to a histogram of your residuals. If your sample size is small you may want to start with a normal assumption.
