ectools/NWKR.py
def _predict(X, X_t, y_t, bw, kernel):
    """helper function for NWKR. It is fully compiled in Numba, and it vectorizes all that is vectorizable to improve speed.

    Args:
        X: the observations to predict from
        X_t: training dataset observations
        y_t: training dataset predictions
        bw: bandwidth(s) - will perform broadcasting
        kernel: a callable that evaluates kernel densities from euclidean distances

    Returns:
        prediction_out: predictions for observations X
        std_out: standard deviations on predictions for observations X
    """
    # initialize arrays for output
    prediction_out = np.empty(X.shape[0])
    std_out = np.empty(X.shape[0])
    # iterate over each row (observation requiring prediction)
    for k in range(X.shape[0]):
        # normal NWKR algorithm
        distances = np.sqrt((((X_t - X[k, :]) / bw) ** 2).sum(axis=1))
        weights = kernel(distances)
        weights = weights / np.sum(weights)  # normalize
        prediction_out[k] = np.sum(weights * y_t)
        std_out[k] = (np.sum(weights * (y_t ** 2)) - prediction_out[k] ** 2) ** .5
    return prediction_out, std_out
helper function for NWKR. It is fully compiled in Numba, and it vectorizes all that is vectorizable to improve speed.

    Args:
        X: the observations to predict from
        X_t: training dataset observations
        y_t: training dataset predictions
        bw: bandwidth(s) - will perform broadcasting
        kernel: a callable that evaluates kernel densities from euclidean distances

    Returns:
        prediction_out: predictions for observations X
        std_out: standard deviations on predictions for observations X
    
helper function for NWKR. It is fully compiled in Numba, and it vectorizes all that is vectorizable to improve speed.
helper function for NWKR . It is fully compiled in Numba and it vectorizes all that is vectorizable to improve speed .
def _predict(X, X_t, y_t, bw, kernel):
    prediction_out = np.empty(X.shape[0])
    std_out = np.empty(X.shape[0])
    for k in range(X.shape[0]):
        distances = np.sqrt((((X_t - X[k, :]) / bw) ** 2).sum(axis=1))
        weights = kernel(distances)
        weights = weights / np.sum(weights)  
        prediction_out[k] = np.sum(weights * y_t)
        std_out[k] = (np.sum(weights * (y_t ** 2)) - prediction_out[k] ** 2) ** .5
    return prediction_out, std_out
def _predict ( X , X_t , y_t , bw , kernel ) : prediction_out = np . empty ( X . shape [ 0 ] ) std_out = np . empty ( X . shape [ 0 ] ) for k in range ( X . shape [ 0 ] ) : distances = np . sqrt ( ( ( ( X_t - X [ k , : ] ) / bw ) ** 2 ) . sum ( axis = 1 ) ) weights = kernel ( distances ) weights = weights / np . sum ( weights ) prediction_out [ k ] = np . sum ( weights * y_t ) std_out [ k ] = ( np . sum ( weights * ( y_t ** 2 ) ) - prediction_out [ k ] ** 2 ) ** .5 return prediction_out , std_out
helper function for NWKR.
helper function for NWKR .
"""helper function for NWKR. It is fully compiled in Numba, and it vectorizes all that is vectorizable to improve speed.

    Args:
        X: the observations to predict from
        X_t: training dataset observations
        y_t: training dataset predictions
        bw: bandwidth(s) - will perform broadcasting
        kernel: a callable that evaluates kernel densities from euclidean distances

    Returns:
        prediction_out: predictions for observations X
        std_out: standard deviations on predictions for observations X
    """ # initialize arrays for output # iterate over each row (observation requiring prediction) # normal NWKR algorithm # normalize
predictions for observations X
std_out: standard deviations on predictions for observations X
predictions for observations X std_out : standard deviations on predictions for observations X
prediction_out
X
the observations to predict from
the observations to predict from
X_t
training dataset observations
training dataset observations
y_t
training dataset predictions
training dataset predictions
bw
will perform broadcasting
will perform broadcasting
kernel
a callable that evaluates kernel densities from euclidean distances
a callable that evaluates kernel densities from euclidean distances