'The cross-validation function with leave-one-out estimator.
Parameters
bw: array_like
Vector of bandwidth values.
func: callable function
Returns the estimator of g(x).  Can be either ``_est_loc_constant``
(local constant) or ``_est_loc_linear`` (local_linear).
Returns
L: float
The value of the CV function.
Notes
Calculates the cross-validation least-squares function. This function
is minimized by compute_bw to calculate the optimal value of `bw`.
For details see p.35 in [2]
.. math:: CV(h)=n^{-1}\sum_{i=1}^{n}(Y_{i}-g_{-i}(X_{i}))^{2}
where :math:`g_{-i}(X_{i})` is the leave-one-out estimator of g(X)
and :math:`h` is the vector of bandwidths'

def cv_loo(self, bw, func):

    LOO_X = LeaveOneOut(self.exog)
    LOO_Y = LeaveOneOut(self.endog).__iter__()
    L = 0
    for (ii, X_not_i) in enumerate(LOO_X):
        Y = next(LOO_Y)
        G = func(bw, endog=Y, exog=(- X_not_i), data_predict=(- self.exog[ii, :]))[0]
        L += ((self.endog[ii] - G) ** 2)
    return (L / self.nobs)
