'Return probability estimates for the test data X.
Parameters
X : array-like, shape (n_query, n_features),                 or (n_query, n_indexed) if metric == \'precomputed\'
Test samples.
Returns
p : array of shape = [n_samples, n_classes], or a list of n_outputs
of such arrays if n_outputs > 1.
The class probabilities of the input samples. Classes are ordered
by lexicographic order.'

def predict_proba(self, X):

    X = check_array(X, accept_sparse='csr')
    (neigh_dist, neigh_ind) = self.kneighbors(X)
    classes_ = self.classes_
    _y = self._y
    if (not self.outputs_2d_):
        _y = self._y.reshape(((-1), 1))
        classes_ = [self.classes_]
    n_samples = X.shape[0]
    weights = _get_weights(neigh_dist, self.weights)
    if (weights is None):
        weights = np.ones_like(neigh_ind)
    all_rows = np.arange(X.shape[0])
    probabilities = []
    for (k, classes_k) in enumerate(classes_):
        pred_labels = _y[:, k][neigh_ind]
        proba_k = np.zeros((n_samples, classes_k.size))
        for (i, idx) in enumerate(pred_labels.T):
            proba_k[(all_rows, idx)] += weights[:, i]
        normalizer = proba_k.sum(axis=1)[:, np.newaxis]
        normalizer[(normalizer == 0.0)] = 1.0
        proba_k /= normalizer
        probabilities.append(proba_k)
    if (not self.outputs_2d_):
        probabilities = probabilities[0]
    return probabilities
