Calculate the false negative rate (1 - sensitivity) and false discovery rate (1 - precision).
512744
def _calculate_fnr_fdr(group):
    
    data = {k: d["value"] for k, d in group.set_index("metric").T.to_dict().items()}
    return pd.DataFrame([{"fnr": data["fn"] / float(data["tp"] + data["fn"]) * 100.0 if data["tp"] > 0 else 0.0,
                          "fdr": data["fp"] / float(data["tp"] + data["fp"]) * 100.0 if data["tp"] > 0 else 0.0,
                          "tpr": "TP: %s FN: %s" % (data["tp"], data["fn"]),
                          "spc": "FP: %s" % (data["fp"])}])
915122
def average_precision(truth, recommend):
    
    if len(truth) == 0:
        if len(recommend) == 0:
            return 1.
        return 0.

    tp = accum = 0.
    for n in range(recommend.size):
        if recommend[n] in truth:
            tp += 1.
            accum += (tp / (n + 1.))
    return accum / truth.size
1363169
def support_false_positive_count(m, m_hat):
    
    m_nnz, m_hat_nnz, intersection_nnz = _nonzero_intersection(m, m_hat)
    return int((m_hat_nnz - intersection_nnz) / 2.0)
1230136
def _sigma_ee_nonrel(self, gam, eps):
        
        s0 = 4 * r0 ** 2 * alpha / (15 * eps)
        x = 4 * eps / (gam ** 2 - 1)
        sigma_nonrel = s0 * self._F(x, gam)
        sigma_nonrel[np.where(eps >= 0.25 * (gam ** 2 - 1.0))] = 0.0
        sigma_nonrel[np.where(gam * np.ones_like(eps) < 1.0)] = 0.0
        return sigma_nonrel / mec2_unit
121195
def overall_error_rate(self):
        

        substitution_rate = metric.substitution_rate(
            Nref=self.overall['Nref'],
            Nsubstitutions=self.overall['Nsubs']
        )

        deletion_rate = metric.deletion_rate(
            Nref=self.overall['Nref'],
            Ndeletions=self.overall['Nfn']
        )

        insertion_rate = metric.insertion_rate(
            Nref=self.overall['Nref'],
            Ninsertions=self.overall['Nfp']
        )

        error_rate = metric.error_rate(
            substitution_rate_value=substitution_rate,
            deletion_rate_value=deletion_rate,
            insertion_rate_value=insertion_rate
        )

        return {
            'error_rate': error_rate,
            'substitution_rate': substitution_rate,
            'deletion_rate': deletion_rate,
            'insertion_rate': insertion_rate
        }
134120
def _compute(self):
        """"""
        positive_vals, negative_vals = self._get_separated_values()

        if self.logarithmic:
            positive_vals = list(
                filter(lambda x: x > self.zero, positive_vals)
            )
            negative_vals = list(
                filter(lambda x: x > self.zero, negative_vals)
            )

        self._compute_box(positive_vals, negative_vals)
        positive_vals = positive_vals or [self.zero]
        negative_vals = negative_vals or [self.zero]

        self._x_pos = [
            x / self._len for x in range(self._len + 1)
        ] if self._len > 1 else [0, 1]  # Center if only one value

        self._points(self._x_pos)

        self.negative_cumulation = [0] * self._len
        self.positive_cumulation = [0] * self._len

        if self.secondary_series:
            positive_vals, negative_vals = self._get_separated_values(True)
            positive_vals = positive_vals or [self.zero]
            negative_vals = negative_vals or [self.zero]
            self.secondary_negative_cumulation = [0] * self._len
            self.secondary_positive_cumulation = [0] * self._len
            self._pre_compute_secondary(positive_vals, negative_vals)

        self._x_pos = [(i + .5) / self._len for i in range(self._len)]
622883
def precision(self):
        
        true_pos = self.matrix[0][0]
        false_pos = self.matrix[1][0]
        return divide(1.0 * true_pos, true_pos + false_pos)
524909
def precision(classifier, testset):
    

    hit = 0
    total = 0
    for example in testset:
        if classifier.classify(example)[0] == classifier.target(example):
            hit += 1
        total += 1
    if total == 0:
        raise ValueError("Empty testset!")
    return hit / float(total)
1237663
private void calculateSCL(double[] x) {
    //System.out.println("Checking at: "+x[0]+" "+x[1]+" "+x[2]);
    value = 0.0;
    Arrays.fill(derivative, 0.0);
    double[] sums = new double[numClasses];
    double[] probs = new double[numClasses];
    double[] counts = new double[numClasses];
    Arrays.fill(counts, 0.0);
    for (int d = 0; d < data.length; d++) {
      //       if (d == testMin) {
      //         d = testMax - 1;
      //         continue;
      //       }
      int[] features = data[d];
      // activation
      Arrays.fill(sums, 0.0);
      for (int c = 0; c < numClasses; c++) {
        for (int f = 0; f < features.length; f++) {
          int i = indexOf(features[f], c);
          sums[c] += x[i];
        }
      }
      // expectation (slower routine replaced by fast way)
      // double total = Double.NEGATIVE_INFINITY;
      // for (int c=0; c<numClasses; c++) {
      //   total = SloppyMath.logAdd(total, sums[c]);
      // }
      double total = ArrayMath.logSum(sums);
      int ld = labels[d];
      for (int c = 0; c < numClasses; c++) {
        probs[c] = Math.exp(sums[c] - total);
        for (int f = 0; f < features.length; f++) {
          int i = indexOf(features[f], c);
          derivative[i] += probs[ld] * probs[c];
        }
      }
      // observed
      for (int f = 0; f < features.length; f++) {
        int i = indexOf(features[f], labels[d]);
        derivative[i] -= probs[ld];
      }
      value -= probs[ld];
    }
    // priors
    if (true) {
      for (int i = 0; i < x.length; i++) {
        double k = 1.0;
        double w = x[i];
        value += k * w * w / 2.0;
        derivative[i] += k * w;
      }
    }
  }
403371
def true_positives(y, y_pred):
    

    y, y_pred = convert_assert(y, y_pred)
    assert_binary_problem(y)

    return np.count_nonzero(y_pred[y == 1] == 1)
632811
def class_wise_error_rate(self, event_label):
        

        deletion_rate = metric.deletion_rate(
            Nref=self.class_wise[event_label]['Nref'],
            Ndeletions=self.class_wise[event_label]['Nfn']
        )

        insertion_rate = metric.insertion_rate(
            Nref=self.class_wise[event_label]['Nref'],
            Ninsertions=self.class_wise[event_label]['Nfp']
        )

        error_rate = metric.error_rate(
            deletion_rate_value=deletion_rate,
            insertion_rate_value=insertion_rate
        )

        return {
            'error_rate': error_rate,
            'deletion_rate': deletion_rate,
            'insertion_rate': insertion_rate
        }
501986
def _q(self, number, precision='.00001'):
        """"""
        if np.isinf(number):
            return np.nan
        else:
            return D(D(number).quantize(D(precision)))
412217
def estimate_frequency_for_one(self, sample_rate: float, nbits=42) -> float:
        
        return self.__estimate_frequency_for_bit(True, sample_rate, nbits)
908207
def get_negative_log_likelihood(self, y_true, X, mask):
        
        input_energy = self.activation(K.dot(X, self.kernel) + self.bias)
        if self.use_boundary:
            input_energy = self.add_boundary_energy(input_energy, mask, self.left_boundary, self.right_boundary)
        energy = self.get_energy(y_true, input_energy, mask)
        logZ = self.get_log_normalization_constant(input_energy, mask, input_length=K.int_shape(X)[1])
        nloglik = logZ + energy
        if mask is not None:
            nloglik = nloglik / K.sum(K.cast(mask, K.floatx()), 1)
        else:
            nloglik = nloglik / K.cast(K.shape(X)[1], K.floatx())
        return nloglik
890674
public double falsePositiveRate() {
    double fpr = 0;
    for(int i = 0; i < confusion.length; i++) {
      fpr += falsePositiveRate(i) * colSum(i);
    }
    return fpr / totalInstances();
  }
762350
def true_negatives(y, y_pred):
    

    y, y_pred = convert_assert(y, y_pred)
    assert_binary_problem(y)

    return np.count_nonzero(y_pred[y == 0] == 0)
367223
def qsnorm(p):
    
    d = p
    if d < 0. or d > 1.:
        print('d not in (1,1) ')
        sys.exit()
    x = 0.
    if (d - 0.5) > 0:
        d = 1. - d
    if (d - 0.5) < 0:
        t2 = -2. * np.log(d)
        t = np.sqrt(t2)
        x = t - old_div((2.515517 + .802853 * t + .010328 * t2),
                        (1. + 1.432788 * t + .189269 * t2 + .001308 * t * t2))
        if p < 0.5:
            x = -x
    return x