class_docstr: Kernel Density Estimation
  
  Read more in the :ref:`User Guide <kernel_density>`.
  
  Parameters
  ----------
  bandwidth : float
      The bandwidth of the kernel.
  
  algorithm : string
      The tree algorithm to use.  Valid options are
      ['kd_tree'|'ball_tree'|'auto'].  Default is 'auto'.
  
  kernel : string
      The kernel to use.  Valid kernels are
      ['gaussian'|'tophat'|'epanechnikov'|'exponential'|'linear'|'cosine']
      Default is 'gaussian'.
  
  metric : string
      The distance metric to use.  Note that not all metrics are
      valid with all algorithms.  Refer to the documentation of
      :class:`BallTree` and :class:`KDTree` for a description of
      available algorithms.  Note that the normalization of the density
      output is correct only for the Euclidean distance metric. Default
      is 'euclidean'.
  
  atol : float
      The desired absolute tolerance of the result.  A larger tolerance will
      generally lead to faster execution. Default is 0.
  
  rtol : float
      The desired relative tolerance of the result.  A larger tolerance will
      generally lead to faster execution.  Default is 1E-8.
  
  breadth_first : boolean
      If true (default), use a breadth-first approach to the problem.
      Otherwise use a depth-first approach.
  
  leaf_size : int
      Specify the leaf size of the underlying tree.  See :class:`BallTree`
      or :class:`KDTree` for details.  Default is 40.
  
  metric_params : dict
      Additional parameters to be passed to the tree for use with the
      metric.  For more information, see the documentation of
      :class:`BallTree` or :class:`KDTree`.
docstr: Generate random samples from the model.
  
  Currently, this is implemented only for gaussian and tophat kernels.
  
  Parameters
  ----------
  n_samples : int, optional
      Number of samples to generate. Defaults to 1.
  
  random_state : RandomState or an int seed (0 by default)
      A random number generator instance.
  
  Returns
  -------
  X : array_like, shape (n_samples, n_features)
      List of samples.
docstr_tok: ["Generate","random","samples","from","the","model",".","Currently",",","this","is","implemented","only","for","gaussian","and","tophat","kernels",".","Parameters","--","--","--","--","--","n_samples",":","int",",","optional","Number","of","samples","to","generate",".","Defaults","to","1.","random_state",":","RandomState","or","an","int","seed","(","0","by","default",")","A","random","number","generator","instance",".","Returns","--","--","--","-","X",":","array_like",",","shape","(","n_samples",",","n_features",")","List","of","samples","."]
code: def sample(self, n_samples=1, random_state=None):
      """Generate random samples from the model.
  
      Currently, this is implemented only for gaussian and tophat kernels.
  
      Parameters
      ----------
      n_samples : int, optional
          Number of samples to generate. Defaults to 1.
  
      random_state : RandomState or an int seed (0 by default)
          A random number generator instance.
  
      Returns
      -------
      X : array_like, shape (n_samples, n_features)
          List of samples.
      """
      # TODO: implement sampling for other valid kernel shapes
      if self.kernel not in ["gaussian", "tophat"]:
          raise NotImplementedError()
  
      data = np.asarray(self.tree_.data)
  
      rng = check_random_state(random_state)
      i = rng.randint(data.shape[0], size=n_samples)
  
      if self.kernel == "gaussian":
          return np.atleast_2d(rng.normal(data[i], self.bandwidth))
  
      elif self.kernel == "tophat":
          # we first draw points from a d-dimensional normal distribution,
          # then use an incomplete gamma function to map them to a uniform
          # d-dimensional tophat distribution.
          dim = data.shape[1]
          X = rng.normal(size=(n_samples, dim))
          s_sq = row_norms(X, squared=True)
          correction = (
              gammainc(0.5 * dim, 0.5 * s_sq) ** (1.0 / dim)
              * self.bandwidth
              / np.sqrt(s_sq)
          )
          return data[i] + X * correction[:, np.newaxis]
  
file_path: catboost/contrib/python/scikit-learn/py2/sklearn/neighbors/kde.py
imports: import numpy
  from scipy.special import gammainc
  from ..base import BaseEstimator
  from ..utils import check_array, check_random_state
  from ..utils.extmath import row_norms
  from .ball_tree import BallTree, DTYPE
  from .kd_tree import KDTree
label_desc: Use image node_id 6 for calling the KernelDensity obj's underlying member method code with example usage: obj.sample(n_samples, random_state) and returns: np, unknown