'Fit a semi-supervised label propagation model based
All the input data is provided matrix X (labeled and unlabeled)
and corresponding label matrix y with a dedicated marker value for
unlabeled samples.
Parameters
X : array-like, shape = [n_samples, n_features]
A {n_samples by n_samples} size matrix will be created from this
y : array_like, shape = [n_samples]
n_labeled_samples (unlabeled points are marked as -1)
All unlabeled samples will be transductively assigned labels
Returns
self : returns an instance of self.'

def fit(self, X, y):

    (X, y) = check_X_y(X, y)
    self.X_ = X
    check_classification_targets(y)
    graph_matrix = self._build_graph()
    classes = np.unique(y)
    classes = classes[(classes != (-1))]
    self.classes_ = classes
    (n_samples, n_classes) = (len(y), len(classes))
    alpha = self.alpha
    if ((self._variant == 'spreading') and ((alpha is None) or (alpha <= 0.0) or (alpha >= 1.0))):
        raise ValueError(('alpha=%s    is    invalid:    it    must    be    inside    the    open    interval    (0,    1)' % alpha))
    y = np.asarray(y)
    unlabeled = (y == (-1))
    self.label_distributions_ = np.zeros((n_samples, n_classes))
    for label in classes:
        self.label_distributions_[((y == label), (classes == label))] = 1
    y_static = np.copy(self.label_distributions_)
    if (self._variant == 'propagation'):
        y_static[unlabeled] = 0
    else:
        y_static *= (1 - alpha)
    l_previous = np.zeros((self.X_.shape[0], n_classes))
    unlabeled = unlabeled[:, np.newaxis]
    if sparse.isspmatrix(graph_matrix):
        graph_matrix = graph_matrix.tocsr()
    for self.n_iter_ in range(self.max_iter):
        if (np.abs((self.label_distributions_ - l_previous)).sum() < self.tol):
            break
        l_previous = self.label_distributions_
        self.label_distributions_ = safe_sparse_dot(graph_matrix, self.label_distributions_)
        if (self._variant == 'propagation'):
            normalizer = np.sum(self.label_distributions_, axis=1)[:, np.newaxis]
            self.label_distributions_ /= normalizer
            self.label_distributions_ = np.where(unlabeled, self.label_distributions_, y_static)
        else:
            self.label_distributions_ = (np.multiply(alpha, self.label_distributions_) + y_static)
    else:
        warnings.warn(('max_iter=%d    was    reached    without    convergence.' % self.max_iter), category=ConvergenceWarning)
        self.n_iter_ += 1
    normalizer = np.sum(self.label_distributions_, axis=1)[:, np.newaxis]
    self.label_distributions_ /= normalizer
    transduction = self.classes_[np.argmax(self.label_distributions_, axis=1)]
    self.transduction_ = transduction.ravel()
    return self
