def predict(self, x, significance=None): ncal_ngt_neq = np.stack([p._get_stats(x) for p in self.predictors], axis=3) ncal_ngt_neq = ncal_ngt_neq.sum(axis=3) p = calc_p(ncal_ngt_neq[:, :, 0], ncal_ngt_neq[:, :, 1], ncal_ngt_neq[:, :, 2], smoothing=self.predictors[0].smoothing) if significance: return p > significance else: return p
def predict(self, x, significance=None): """Predict the output values for a set of input patterns. Parameters ---------- x : numpy array of shape [n_samples, n_features] Inputs of patters for which to predict output values. significance : float or None Significance level (maximum allowed error rate) of predictions. Should be a float between 0 and 1. If ``None``, then the p-values are output rather than the predictions. Returns ------- p : numpy array of shape [n_samples, n_classes] If significance is ``None``, then p contains the p-values for each sample-class pair; if significance is a float between 0 and 1, then p is a boolean array denoting which labels are included in the prediction sets. """ # TODO: if x == self.last_x ... n_test_objects = x.shape[0] p = np.zeros((n_test_objects, self.classes.size)) ncal_ngt_neq = self._get_stats(x) for i in range(len(self.classes)): for j in range(n_test_objects): p[j, i] = calc_p( ncal_ngt_neq[j, i, 0], ncal_ngt_neq[j, i, 1], ncal_ngt_neq[j, i, 2], self.smoothing, ) if significance is not None: return p > significance else: return p