class_docstr: LabelSpreading model for semi-supervised learning
  
  This model is similar to the basic Label Propgation algorithm,
  but uses affinity matrix based on the normalized graph Laplacian
  and soft clamping across the labels.
  
  Read more in the :ref:`User Guide <label_propagation>`.
  
  Parameters
  ----------
  kernel : {'knn', 'rbf'}
      String identifier for kernel function to use.
      Only 'rbf' and 'knn' kernels are currently supported.
  
  gamma : float
    parameter for rbf kernel
  
  n_neighbors : integer > 0
    parameter for knn kernel
  
  alpha : float
    clamping factor
  
  max_iter : float
    maximum number of iterations allowed
  
  tol : float
    Convergence tolerance: threshold to consider the system at steady
    state
  
  n_jobs : int, optional (default = 1)
      The number of parallel jobs to run.
      If ``-1``, then the number of jobs is set to the number of CPU cores.
  
  Attributes
  ----------
  X_ : array, shape = [n_samples, n_features]
      Input array.
  
  classes_ : array, shape = [n_classes]
      The distinct labels used in classifying instances.
  
  label_distributions_ : array, shape = [n_samples, n_classes]
      Categorical distribution for each item.
  
  transduction_ : array, shape = [n_samples]
      Label assigned to each item via the transduction.
  
  n_iter_ : int
      Number of iterations run.
  
  Examples
  --------
  >>> from sklearn import datasets
  >>> from sklearn.semi_supervised import LabelSpreading
  >>> label_prop_model = LabelSpreading()
  >>> iris = datasets.load_iris()
  >>> random_unlabeled_points = np.where(np.random.randint(0, 2,
  ...    size=len(iris.target)))
  >>> labels = np.copy(iris.target)
  >>> labels[random_unlabeled_points] = -1
  >>> label_prop_model.fit(iris.data, labels)
  ... # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
  LabelSpreading(...)
  
  References
  ----------
  Dengyong Zhou, Olivier Bousquet, Thomas Navin Lal, Jason Weston,
  Bernhard Schoelkopf. Learning with local and global consistency (2004)
  http://citeseer.ist.psu.edu/viewdoc/summary?doi=10.1.1.115.3219
  
  See Also
  --------
  LabelPropagation : Unregularized graph based semi-supervised learning
class_docstr_tok: ["LabelSpreading","model","for","semi-supervised","learning","This","model","is","similar","to","the","basic","Label","Propgation","algorithm",",","but","uses","affinity","matrix","based","on","the","normalized","graph","Laplacian","and","soft","clamping","across","the","labels",".","Read","more","in","the",":","ref",":","`","User","Guide","<","label_propagation",">","`",".","Parameters","--","--","--","--","--","kernel",":","{","'knn","'",",","'rbf","'","}","String","identifier","for","kernel","function","to","use",".","Only","'rbf","'","and","'knn","'","kernels","are","currently","supported",".","gamma",":","float","parameter","for","rbf","kernel","n_neighbors",":","integer",">","0","parameter","for","knn","kernel","alpha",":","float","clamping","factor","max_iter",":","float","maximum","number","of","iterations","allowed","tol",":","float","Convergence","tolerance",":","threshold","to","consider","the","system","at","steady","state","n_jobs",":","int",",","optional","(","default","=","1",")","The","number","of","parallel","jobs","to","run",".","If","``","-1","``",",","then","the","number","of","jobs","is","set","to","the","number","of","CPU","cores",".","Attributes","--","--","--","--","--","X_",":","array",",","shape","=","[","n_samples",",","n_features","]","Input","array",".","classes_",":","array",",","shape","=","[","n_classes","]","The","distinct","labels","used","in","classifying","instances",".","label_distributions_",":","array",",","shape","=","[","n_samples",",","n_classes","]","Categorical","distribution","for","each","item",".","transduction_",":","array",",","shape","=","[","n_samples","]","Label","assigned","to","each","item","via","the","transduction",".","n_iter_",":","int","Number","of","iterations","run",".","Examples","--","--","--","--",">",">",">","from","sklearn","import","datasets",">",">",">","from","sklearn.semi_supervised","import","LabelSpreading",">",">",">","label_prop_model","=","LabelSpreading","(",")",">",">",">","iris","=","datasets.load_iris","(",")",">",">",">","random_unlabeled_points","=","np.where","(","np.random.randint","(","0",",","2",",","...","size=len","(","iris.target",")",")",")",">",">",">","labels","=","np.copy","(","iris.target",")",">",">",">","labels","[","random_unlabeled_points","]","=","-1",">",">",">","label_prop_model.fit","(","iris.data",",","labels",")","...","#","doctest",":","+NORMALIZE_WHITESPACE","+ELLIPSIS","LabelSpreading","(","...",")","References","--","--","--","--","--","Dengyong","Zhou",",","Olivier","Bousquet",",","Thomas","Navin","Lal",",","Jason","Weston",",","Bernhard","Schoelkopf",".","Learning","with","local","and","global","consistency","(","2004",")","http",":","\/\/citeseer.ist.psu.edu\/viewdoc\/summary","?","doi=10.1.1.115.3219","See","Also","--","--","--","--","LabelPropagation",":","Unregularized","graph","based","semi-supervised","learning"]
docstr: Graph matrix for Label Spreading computes the graph laplacian
docstr_tok: ["Graph","matrix","for","Label","Spreading","computes","the","graph","laplacian"]
code: def _build_graph(self):
      """Graph matrix for Label Spreading computes the graph laplacian"""
      # compute affinity matrix (or gram matrix)
      if self.kernel == "knn":
          self.nn_fit = None
      n_samples = self.X_.shape[0]
      affinity_matrix = self._get_kernel(self.X_)
      laplacian = graph_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  # set diag to 0.0
      return laplacian
  
imports: from abc import ABCMeta, abstractmethod
  import numpy
  from scipy import sparse
  from ..base import BaseEstimator, ClassifierMixin
  from ..externals import six
  from ..metrics.pairwise import rbf_kernel
  from ..neighbors.unsupervised import NearestNeighbors
  from ..utils.extmath import safe_sparse_dot
  from ..utils.graph import graph_laplacian
  from ..utils.multiclass import check_classification_targets
  from ..utils.validation import check_X_y, check_is_fitted, check_array
label_desc: Use image node_id 2 for calling the LabelSpreading obj's underlying member method code with example usage: obj._build_graph() and returns: laplacian