parameters: (self, X)
return_statement: return probabilities
docstring: Return probability estimates for the test data X.
  
          Parameters
          ----------
          X : array-like, shape (n_queries, n_features), \
                  or (n_queries, n_indexed) if metric == 'precomputed'
              Test samples.
  
          Returns
          -------
          p : array of shape = [n_queries, 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.
docstring_summary: Return probability estimates for the test data X.
docstring_tokens: Return probability estimates for the test data X .
function: def predict_proba(self, X):
          """Return probability estimates for the test data X.
  
          Parameters
          ----------
          X : array-like, shape (n_queries, n_features), \
                  or (n_queries, n_indexed) if metric == 'precomputed'
              Test samples.
  
          Returns
          -------
          p : array of shape = [n_queries, 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.
          """
  
          X = check_array(X, accept_sparse='csr')
          n_queries = _num_samples(X)
  
          neigh_dist, neigh_ind = self.radius_neighbors(X)
          outlier_mask = np.zeros(n_queries, dtype=np.bool)
          outlier_mask[:] = [len(nind) == 0 for nind in neigh_ind]
          outliers = np.flatnonzero(outlier_mask)
          inliers = np.flatnonzero(~outlier_mask)
  
          classes_ = self.classes_
          _y = self._y
          if not self.outputs_2d_:
              _y = self._y.reshape((-1, 1))
              classes_ = [self.classes_]
  
          if self.outlier_label_ is None and outliers.size > 0:
              raise ValueError('No neighbors found for test samples %r, '
                               'you can try using larger radius, '
                               'giving a label for outliers, '
                               'or considering removing them from your dataset.'
                               % outliers)
  
          weights = _get_weights(neigh_dist, self.weights)
          if weights is not None:
              weights = weights[inliers]
  
          probabilities = []
          # iterate over multi-output, measure probabilities of the k-th output.
          for k, classes_k in enumerate(classes_):
              pred_labels = np.zeros(len(neigh_ind), dtype=object)
              pred_labels[:] = [_y[ind, k] for ind in neigh_ind]
  
              proba_k = np.zeros((n_queries, classes_k.size))
              proba_inl = np.zeros((len(inliers), classes_k.size))
  
              # samples have different size of neighbors within the same radius
              if weights is None:
                  for i, idx in enumerate(pred_labels[inliers]):
                      proba_inl[i, :] = np.bincount(idx,
                                                    minlength=classes_k.size)
              else:
                  for i, idx in enumerate(pred_labels[inliers]):
                      proba_inl[i, :] = np.bincount(idx,
                                                    weights[i],
                                                    minlength=classes_k.size)
              proba_k[inliers, :] = proba_inl
  
              if outliers.size > 0:
                  _outlier_label = self.outlier_label_[k]
                  label_index = np.flatnonzero(classes_k == _outlier_label)
                  if label_index.size == 1:
                      proba_k[outliers, label_index[0]] = 1.0
                  else:
                      warnings.warn('Outlier label {} is not in training '
                                    'classes. All class probabilities of '
                                    'outliers will be assigned with 0.'
                                    ''.format(self.outlier_label_[k]))
  
              # normalize 'votes' into real [0,1] probabilities
              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
function_tokens: def predict_proba ( self , X ) : X = check_array ( X , accept_sparse = 'csr' ) n_queries = _num_samples ( X ) neigh_dist , neigh_ind = self . radius_neighbors ( X ) outlier_mask = np . zeros ( n_queries , dtype = np . bool ) outlier_mask [ : ] = [ len ( nind ) == 0 for nind in neigh_ind ] outliers = np . flatnonzero ( outlier_mask ) inliers = np . flatnonzero ( ~ outlier_mask ) classes_ = self . classes_ _y = self . _y if not self . outputs_2d_ : _y = self . _y . reshape ( ( - 1 , 1 ) ) classes_ = [ self . classes_ ] if self . outlier_label_ is None and outliers . size > 0 : raise ValueError ( 'No neighbors found for test samples %r, ' 'you can try using larger radius, ' 'giving a label for outliers, ' 'or considering removing them from your dataset.' % outliers ) weights = _get_weights ( neigh_dist , self . weights ) if weights is not None : weights = weights [ inliers ] probabilities = [ ] # iterate over multi-output, measure probabilities of the k-th output. for k , classes_k in enumerate ( classes_ ) : pred_labels = np . zeros ( len ( neigh_ind ) , dtype = object ) pred_labels [ : ] = [ _y [ ind , k ] for ind in neigh_ind ] proba_k = np . zeros ( ( n_queries , classes_k . size ) ) proba_inl = np . zeros ( ( len ( inliers ) , classes_k . size ) ) # samples have different size of neighbors within the same radius if weights is None : for i , idx in enumerate ( pred_labels [ inliers ] ) : proba_inl [ i , : ] = np . bincount ( idx , minlength = classes_k . size ) else : for i , idx in enumerate ( pred_labels [ inliers ] ) : proba_inl [ i , : ] = np . bincount ( idx , weights [ i ] , minlength = classes_k . size ) proba_k [ inliers , : ] = proba_inl if outliers . size > 0 : _outlier_label = self . outlier_label_ [ k ] label_index = np . flatnonzero ( classes_k == _outlier_label ) if label_index . size == 1 : proba_k [ outliers , label_index [ 0 ] ] = 1.0 else : warnings . warn ( 'Outlier label {} is not in training ' 'classes. All class probabilities of ' 'outliers will be assigned with 0.' '' . format ( self . outlier_label_ [ k ] ) ) # normalize 'votes' into real [0,1] probabilities 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