'estimate the orthogonal polynomial approximation to the density'

def fit(self, x, polybase=None, order=5, limits=None):

    if (polybase is None):
        polys = self.polys[:order]
    else:
        self.polybase = polybase
        self.polys = polys = [polybase(i) for i in range(order)]
    if (not hasattr(self, 'offsetfac')):
        self.offsetfac = polys[0].offsetfactor
    (xmin, xmax) = (x.min(), x.max())
    if (limits is None):
        self.offset = offset = ((xmax - xmin) * self.offsetfac)
        limits = self.limits = ((xmin - offset), (xmax + offset))
    interval_length = (limits[1] - limits[0])
    xinterval = (xmax - xmin)
    self.shrink = (1.0 / interval_length)
    offset = ((interval_length - xinterval) / 2.0)
    self.shift = (xmin - offset)
    self.x = x = self._transform(x)
    coeffs = [p(x).mean() for p in polys]
    self.coeffs = coeffs
    self.polys = polys
    self._verify()
    return self
