'Graph matrix for Label Spreading computes the graph laplacian'

def _build_graph(self):

    if (self.kernel == 'knn'):
        self.nn_fit = None
    n_samples = self.X_.shape[0]
    affinity_matrix = self._get_kernel(self.X_)
    laplacian = sparse.csgraph.laplacian(affinity_matrix, normed=True)
    laplacian = (- laplacian)
    if sparse.isspmatrix(laplacian):
        diag_mask = (laplacian.row == laplacian.col)
        laplacian.data[diag_mask] = 0.0
    else:
        laplacian.flat[::(n_samples + 1)] = 0.0
    return laplacian
