jiahuimbzuai/CoQuIR huggingface dataset:
//  [python]
def jaccard_similarity_score(self, y_true, y_pred, normalize=True, sample_weight=None):
        """
        Method calculates the Jaccard similarity score and output it using MCenter as single value.

        :Example:

        >>> from parallelm.mlops import mlops
        >>> labels_pred = [1, 0, 1] # prediction labels
        >>> labels = [0, 1, 0] # actual labels
        >>> mlops.metrics.jaccard_similarity_score(labels, labels_pred)

        :param y_true: Ground truth (correct) target values.
        :param y_pred: Estimated targets as returned by a classifier.
        :param normalize: If False, return the sum of the Jaccard similarity coefficient over the sample set. Otherwise, return the average.
        :param sample_weight: Sample weights.
        :return: Jaccard similarity score
        :raises: MLOpsStatisticsException
        """
        # need to import only on run time.
        from parallelm.mlops import mlops as mlops
        import sklearn

        jaccard_similarity_score = sklearn.metrics.jaccard_similarity_score(y_true=y_true, y_pred=y_pred,
                                                                            normalize=normalize,
                                                                            sample_weight=sample_weight)

        mlops.set_stat(ClassificationMetrics.JACCARD_SIMILARITY_SCORE, data=jaccard_similarity_score)

        return jaccard_similarity_score
//  [python]
def jaccard_similarity_score(self, y_true, y_pred, normalize=True, sample_weight=None):
        """
        Method calculates the Jaccard similarity score and output it using MCenter as single value.

        :Example:

        >>> from parallelm.mlops import mlops
        >>> labels_pred = [1, 0, 1] # prediction labels
        >>> labels = [0, 1, 0] # actual labels
        >>> mlops.metrics.jaccard_similarity_score(labels, labels_pred)

        :param y_true: Ground truth (correct) target values.
        :param y_pred: Estimated targets as returned by a classifier.
        :param normalize: If False, return the sum of the Jaccard similarity coefficient over the sample set. Otherwise, return the average.
        :param sample_weight: Sample weights.
        :return: Jaccard similarity score
        :raises: MLOpsStatisticsException
        """
        # need to import only on run time.
        from parallelm.mlops import mlops as mlops
        import sklearn

        jaccard_similarity_score = sklearn.metrics.jaccard_score(y_true=y_true, y_pred=y_pred,
                                                                            average='macro' if normalize else None,
                                                                            sample_weight=sample_weight)

        mlops.set_stat(ClassificationMetrics.JACCARD_SIMILARITY_SCORE, data=jaccard_similarity_score)

        return jaccard_similarity_score
//  [python]
def get_jaccard(self, progress=True):
        import sklearn.metrics
        N = len(self.df)
        J = np.zeros((N,N))
        from easydev import progress_bar
        pb = progress_bar(N)
        for ic, i in enumerate(self.df.index):
            for jc, j in enumerate(self.df.index):
                J[ic][jc] = sklearn.metrics.jaccard_similarity_score(self.df.ix[i], self.df.ix[j])
            pb.animate(1+ic)
        return J
//  [python]
def get_jaccard(self, progress=True):
        import sklearn.metrics
        N = len(self.df)
        J = np.zeros((N,N))
        from easydev import progress_bar
        pb = progress_bar(N)
        for ic, i in enumerate(self.df.index):
            for jc, j in enumerate(self.df.index):
                J[ic][jc] = sklearn.metrics.jaccard_score(self.df.ix[i], self.df.ix[j])
            pb.animate(1+ic)
        return J
//  [python]
def test_jaccard_similarity_score(self):
        result = self.df.metrics.jaccard_similarity_score()
        expected = metrics.jaccard_similarity_score(self.target, self.pred)
        self.assertEqual(result, expected)

        result = self.df.metrics.jaccard_similarity_score(normalize=False)
        expected = metrics.jaccard_similarity_score(self.target, self.pred, normalize=False)
        self.assertEqual(result, expected)
//  [python]
def test_jaccard_similarity_score(self):
        result = self.df.metrics.jaccard_score()
        expected = metrics.jaccard_score(self.target, self.pred)
        self.assertEqual(result, expected)

        result = self.df.metrics.jaccard_score(normalize=False)
        expected = metrics.jaccard_score(self.target, self.pred, normalize=False)
        self.assertEqual(result, expected)
//  [python]
def evaluate(pred, gt):
    pred = np.round(pred).astype(int).flatten()
    gt = gt.flatten()

    fmes = sklearn.metrics.f1_score(gt, pred)
    acc = sklearn.metrics.accuracy_score(gt, pred)
    rec = sklearn.metrics.recall_score(gt, pred)
    cm = sklearn.metrics.confusion_matrix(gt, pred)
    jacc = sklearn.metrics.jaccard_similarity_score(gt, pred)
 
    return fmes, acc, rec, jacc, cm
//  [python]
def evaluate(pred, gt):
    pred = np.round(pred).astype(int).flatten()
    gt = gt.flatten()

    fmes = sklearn.metrics.f1_score(gt, pred)
    acc = sklearn.metrics.accuracy_score(gt, pred)
    rec = sklearn.metrics.recall_score(gt, pred)
    cm = sklearn.metrics.confusion_matrix(gt, pred)
    jacc = sklearn.metrics.jaccard_score(gt, pred)
 
    return fmes, acc, rec, jacc, cm
//  [python]
def cal_metric(y_true, y_pred):
    ma_p, ma_r, ma_f1, _ = metrics.precision_recall_fscore_support(y_true, y_pred, average='macro')
    # mi_p, mi_r, mi_f1, _ = metrics.precision_recall_fscore_support(y_true, y_pred, average='micro')
    acc = metrics.accuracy_score(y_true,y_pred)
    jaccard = metrics.jaccard_similarity_score(y_true, y_pred)
    hamming_loss = metrics.hamming_loss(y_true, y_pred)
    # average_f1 = (ma_f1 + mi_f1)/2 * 100
    return [(ma_p, ma_r, ma_f1), acc, jaccard, hamming_loss]
//  [python]
def cal_metric(y_true, y_pred):
    ma_p, ma_r, ma_f1, _ = metrics.precision_recall_fscore_support(y_true, y_pred, average='macro')
    # mi_p, mi_r, mi_f1, _ = metrics.precision_recall_fscore_support(y_true, y_pred, average='micro')
    acc = metrics.accuracy_score(y_true,y_pred)
    jaccard = metrics.jaccard_score(y_true, y_pred, average='macro')
    hamming_loss = metrics.hamming_loss(y_true, y_pred)
    # average_f1 = (ma_f1 + mi_f1)/2 * 100
    return [(ma_p, ma_r, ma_f1), acc, jaccard, hamming_loss]
//  [python]
def test_mlops_jaccard_sim_score_apis():
    pm.init(ctx=None, mlops_mode=MLOpsMode.STAND_ALONE)

    labels_pred = [1, 0, 1, 1, 1, 0]
    labels_actual = [0, 1, 0, 0, 0, 1]

    jss = sklearn.metrics.jaccard_similarity_score(labels_actual, labels_pred)

    # first way
    pm.set_stat(ClassificationMetrics.JACCARD_SIMILARITY_SCORE, jss)

    # second way
    pm.metrics.jaccard_similarity_score(labels_actual, labels_pred)

    # should throw error if not numeric number is provided
    with pytest.raises(MLOpsStatisticsException):
        pm.set_stat(ClassificationMetrics.JACCARD_SIMILARITY_SCORE, [1, 2, 3])

    # should throw error if labels predicted is different length than actuals
    with pytest.raises(ValueError):
        labels_prob_missing_values = [1, 0, 1, 1]
        pm.metrics.jaccard_similarity_score(y_true=labels_actual, y_pred=labels_prob_missing_values)

    sample_weight = [0.9, 0.1, 0.5, 0.9, 1.0, 0]

    # testing with sample weights as well
    pm.metrics.jaccard_similarity_score(y_true=labels_actual,
                                        y_pred=labels_pred,
                                        sample_weight=sample_weight)

    pm.done()
//  [python]
def test_mlops_jaccard_sim_score_apis():
    pm.init(ctx=None, mlops_mode=MLOpsMode.STAND_ALONE)

    labels_pred = [1, 0, 1, 1, 1, 0]
    labels_actual = [0, 1, 0, 0, 0, 1]

    jss = sklearn.metrics.jaccard_score(labels_actual, labels_pred)

    # first way
    pm.set_stat(ClassificationMetrics.JACCARD_SIMILARITY_SCORE, jss)

    # second way
    pm.metrics.jaccard_similarity_score(labels_actual, labels_pred)

    # should throw error if not numeric number is provided
    with pytest.raises(MLOpsStatisticsException):
        pm.set_stat(ClassificationMetrics.JACCARD_SIMILARITY_SCORE, [1, 2, 3])

    # should throw error if labels predicted is different length than actuals
    with pytest.raises(ValueError):
        labels_prob_missing_values = [1, 0, 1, 1]
        pm.metrics.jaccard_similarity_score(y_true=labels_actual, y_pred=labels_prob_missing_values)

    sample_weight = [0.9, 0.1, 0.5, 0.9, 1.0, 0]

    # testing with sample weights as well
    pm.metrics.jaccard_similarity_score(y_true=labels_actual,
                                        y_pred=labels_pred,
                                        sample_weight=sample_weight)

    pm.done()
//  [python]
def binary_functions(eval_type, ravel_y_true: [str], ravel_y_pred: [str],
                     y_prob_pos: np.ndarray, pos_label: str) -> dict:
    return {
        '{} DET curve'.format(eval_type): eval.det_curve(ravel_y_true, y_prob_pos,
                                                           pos_label=pos_label),
        '{} F1 binary'.format(eval_type): eval.f1_score(ravel_y_true, ravel_y_pred,
                                                          pos_label=pos_label),
        '{} hamming loss binary'.format(eval_type): eval.hamming_loss(ravel_y_true, ravel_y_pred,
                                                                        pos_label=pos_label),
        '{} jaccard score binary'.format(eval_type): eval.jaccard_similarity_score(ravel_y_true, ravel_y_pred,
                                                                          pos_label=pos_label)
    }
//  [python]
def binary_functions(eval_type, ravel_y_true: [str], ravel_y_pred: [str],
                     y_prob_pos: np.ndarray, pos_label: str) -> dict:
    return {
        '{} DET curve'.format(eval_type): eval.det_curve(ravel_y_true, y_prob_pos,
                                                           pos_label=pos_label),
        '{} F1 binary'.format(eval_type): eval.f1_score(ravel_y_true, ravel_y_pred,
                                                          pos_label=pos_label),
        '{} hamming loss binary'.format(eval_type): eval.hamming_loss(ravel_y_true, ravel_y_pred,
                                                                        pos_label=pos_label),
        '{} jaccard score binary'.format(eval_type): eval.jaccard_score(ravel_y_true, ravel_y_pred,
                                                                          pos_label=pos_label)
    }
//  [python]
def test_classifier_chain_vs_independent_models():
    # Verify that an ensemble of classifier chains (each of length
    # N) can achieve a higher Jaccard similarity score than N independent
    # models
    X, Y = generate_multilabel_dataset_with_correlations()
    X_train = X[:600, :]
    X_test = X[600:, :]
    Y_train = Y[:600, :]
    Y_test = Y[600:, :]

    ovr = OneVsRestClassifier(LogisticRegression())
    ovr.fit(X_train, Y_train)
    Y_pred_ovr = ovr.predict(X_test)

    chain = ClassifierChain(LogisticRegression())
    chain.fit(X_train, Y_train)
    Y_pred_chain = chain.predict(X_test)

    assert (jaccard_similarity_score(Y_test, Y_pred_chain, average='samples') >
            jaccard_similarity_score(Y_test, Y_pred_ovr, average='samples'))
//  [python]
def test_classifier_chain_vs_independent_models():
    # Verify that an ensemble of classifier chains (each of length
    # N) can achieve a higher Jaccard similarity score than N independent
    # models
    X, Y = generate_multilabel_dataset_with_correlations()
    X_train = X[:600, :]
    X_test = X[600:, :]
    Y_train = Y[:600, :]
    Y_test = Y[600:, :]

    ovr = OneVsRestClassifier(LogisticRegression())
    ovr.fit(X_train, Y_train)
    Y_pred_ovr = ovr.predict(X_test)

    chain = ClassifierChain(LogisticRegression())
    chain.fit(X_train, Y_train)
    Y_pred_chain = chain.predict(X_test)

    assert (jaccard_score(Y_test, Y_pred_chain, average='samples') >
            jaccard_score(Y_test, Y_pred_ovr, average='samples'))
//  [python]
def test_base_chain_crossval_fit_and_predict():
    # Fit chain with cross_val_predict and verify predict
    # performance
    X, Y = generate_multilabel_dataset_with_correlations()

    for chain in [ClassifierChain(LogisticRegression()),
                  RegressorChain(Ridge())]:
        chain.fit(X, Y)
        chain_cv = clone(chain).set_params(cv=3)
        chain_cv.fit(X, Y)
        Y_pred_cv = chain_cv.predict(X)
        Y_pred = chain.predict(X)

        assert Y_pred_cv.shape == Y_pred.shape
        assert not np.all(Y_pred == Y_pred_cv)
        if isinstance(chain, ClassifierChain):
            assert jaccard_similarity_score(Y, Y_pred_cv, average='samples') > .4
        else:
            assert mean_squared_error(Y, Y_pred_cv) < .25
//  [python]
def test_base_chain_crossval_fit_and_predict():
    # Fit chain with cross_val_predict and verify predict
    # performance
    X, Y = generate_multilabel_dataset_with_correlations()

    for chain in [ClassifierChain(LogisticRegression()),
                  RegressorChain(Ridge())]:
        chain.fit(X, Y)
        chain_cv = clone(chain).set_params(cv=3)
        chain_cv.fit(X, Y)
        Y_pred_cv = chain_cv.predict(X)
        Y_pred = chain.predict(X)

        assert Y_pred_cv.shape == Y_pred.shape
        assert not np.all(Y_pred == Y_pred_cv)
        if isinstance(chain, ClassifierChain):
            assert jaccard_score(Y, Y_pred_cv, average='samples') > .4
        else:
            assert mean_squared_error(Y, Y_pred_cv) < .25
//  [python]
def common_functions(eval_type, y_true: np.ndarray, y_pred: np.ndarray, y_prob: np.ndarray) -> dict:
    return {
        '{} accuracy'.format(eval_type): eval.accuracy_score(y_true, y_pred),
        '{} macro average precision score'.format(eval_type): eval.average_precision_score(y_true, y_prob),
        '{} F1 micro'.format(eval_type): float(eval.f1_score(y_true, y_pred, average='micro')),
        '{} F1 macro'.format(eval_type): float(eval.f1_score(y_true, y_pred, average='macro')),
        '{} F1 weighted'.format(eval_type): float(eval.f1_score(y_true, y_pred, average='weighted')),
        '{} hamming loss micro'.format(eval_type): eval.hamming_loss(y_true, y_pred),
        '{} hamming loss macro'.format(eval_type): eval.hamming_loss(y_true, y_pred),
        '{} hamming loss weighted'.format(eval_type): eval.hamming_loss(y_true, y_pred),
        '{} jaccard score micro'.format(eval_type): eval.jaccard_similarity_score(y_true, y_pred),
        '{} jaccard score macro'.format(eval_type): eval.jaccard_similarity_score(y_true, y_pred),
        '{} jaccard score weighted'.format(eval_type): eval.jaccard_similarity_score(y_true, y_pred)
    }
//  [python]
def common_functions(eval_type, y_true: np.ndarray, y_pred: np.ndarray, y_prob: np.ndarray) -> dict:
    return {
        '{} accuracy'.format(eval_type): eval.accuracy_score(y_true, y_pred),
        '{} macro average precision score'.format(eval_type): eval.average_precision_score(y_true, y_prob),
        '{} F1 micro'.format(eval_type): float(eval.f1_score(y_true, y_pred, average='micro')),
        '{} F1 macro'.format(eval_type): float(eval.f1_score(y_true, y_pred, average='macro')),
        '{} F1 weighted'.format(eval_type): float(eval.f1_score(y_true, y_pred, average='weighted')),
        '{} hamming loss micro'.format(eval_type): eval.hamming_loss(y_true, y_pred),
        '{} hamming loss macro'.format(eval_type): eval.hamming_loss(y_true, y_pred),
        '{} hamming loss weighted'.format(eval_type): eval.hamming_loss(y_true, y_pred),
        '{} jaccard score micro'.format(eval_type): eval.jaccard_score(y_true, y_pred, average='micro'),
        '{} jaccard score macro'.format(eval_type): eval.jaccard_score(y_true, y_pred, average='macro'),
        '{} jaccard score weighted'.format(eval_type): eval.jaccard_score(y_true, y_pred, average='weighted')
    }
//  [python]
def on_epoch_end(self, _, logs={}):
		metrics_values = defaultdict(list)

		for i in range(len(self._valid_dataset)):
			
			image, gt_mask = self._valid_dataset[i]
			image = np.expand_dims(image, axis=0)
			pr_mask = self.model.predict(image)

			y_pred = np.argmax(pr_mask.squeeze(), axis=-1).astype(np.uint8)
			y_true = np.argmax(gt_mask.squeeze(), axis=-1).astype(np.uint8)
					
			metrics = lsd_metrics(
				y_pred,
				y_true,
				self._n_classes)

			for k in metrics._fields:
				metrics_values[k].append(float(getattr(metrics, k)))

			y_true_flat = y_true.reshape((y_true.size, ))
			y_pred_flat = y_pred.reshape((y_pred.size, ))

			if False:
				for k in ('micro', 'macro', 'weighted'):
					metrics_values['precision-%s' % k].append(
						sklearn.metrics.precision_score(y_true_flat, y_pred_flat, average=k))
					metrics_values['recall-%s' % k].append(
						sklearn.metrics.recall_score(y_true_flat, y_pred_flat, average=k))
					metrics_values['jaccard-%s' % k].append(
						sklearn.metrics.jaccard_similarity_score(y_true_flat, y_pred_flat, average=k))

			metrics_values['matthews'].append(
				sklearn.metrics.matthews_corrcoef(y_true_flat, y_pred_flat))


		for k, v in metrics_values.items():
			log_custom_metric(key="val_" + k, value=np.mean(np.array(v)))

		if self._save_path is not None:
			current = np.mean(np.array(metrics_values['matthews']))
			if current > self._best:
				self.model.save(str(self._save_path), overwrite=True)
				self._best = current
//  [python]
def on_epoch_end(self, _, logs={}):
		metrics_values = defaultdict(list)

		for i in range(len(self._valid_dataset)):
			
			image, gt_mask = self._valid_dataset[i]
			image = np.expand_dims(image, axis=0)
			pr_mask = self.model.predict(image)

			y_pred = np.argmax(pr_mask.squeeze(), axis=-1).astype(np.uint8)
			y_true = np.argmax(gt_mask.squeeze(), axis=-1).astype(np.uint8)
					
			metrics = lsd_metrics(
				y_pred,
				y_true,
				self._n_classes)

			for k in metrics._fields:
				metrics_values[k].append(float(getattr(metrics, k)))

			y_true_flat = y_true.reshape((y_true.size, ))
			y_pred_flat = y_pred.reshape((y_pred.size, ))

			if False:
				for k in ('micro', 'macro', 'weighted'):
					metrics_values['precision-%s' % k].append(
						sklearn.metrics.precision_score(y_true_flat, y_pred_flat, average=k))
					metrics_values['recall-%s' % k].append(
						sklearn.metrics.recall_score(y_true_flat, y_pred_flat, average=k))
					metrics_values['jaccard-%s' % k].append(
						sklearn.metrics.jaccard_score(y_true_flat, y_pred_flat, average=k))

			metrics_values['matthews'].append(
				sklearn.metrics.matthews_corrcoef(y_true_flat, y_pred_flat))


		for k, v in metrics_values.items():
			log_custom_metric(key="val_" + k, value=np.mean(np.array(v)))

		if self._save_path is not None:
			current = np.mean(np.array(metrics_values['matthews']))
			if current > self._best:
				self.model.save(str(self._save_path), overwrite=True)
				self._best = current
//  [python]
def test_classifier_chain_vs_independent_models():
    # Verify that an ensemble of classifier chains (each of length
    # N) can achieve a higher Jaccard similarity score than N independent
    # models
    X, Y = generate_multilabel_dataset_with_correlations()
    X_train = X[:600, :]
    X_test = X[600:, :]
    Y_train = Y[:600, :]
    Y_test = Y[600:, :]

    ovr = OneVsRestClassifier(LogisticRegression())
    ovr.fit(X_train, Y_train)
    Y_pred_ovr = ovr.predict(X_test)

    chain = ClassifierChain(LogisticRegression())
    chain.fit(X_train, Y_train)
    Y_pred_chain = chain.predict(X_test)

    assert jaccard_similarity_score(Y_test, Y_pred_chain, average="samples") > jaccard_similarity_score(
        Y_test, Y_pred_ovr, average="samples"
    )
//  [python]
def test_classifier_chain_vs_independent_models():
    # Verify that an ensemble of classifier chains (each of length
    # N) can achieve a higher Jaccard similarity score than N independent
    # models
    X, Y = generate_multilabel_dataset_with_correlations()
    X_train = X[:600, :]
    X_test = X[600:, :]
    Y_train = Y[:600, :]
    Y_test = Y[600:, :]

    ovr = OneVsRestClassifier(LogisticRegression())
    ovr.fit(X_train, Y_train)
    Y_pred_ovr = ovr.predict(X_test)

    chain = ClassifierChain(LogisticRegression())
    chain.fit(X_train, Y_train)
    Y_pred_chain = chain.predict(X_test)

    assert jaccard_score(Y_test, Y_pred_chain, average="samples") > jaccard_score(
        Y_test, Y_pred_ovr, average="samples"
    )
//  [python]
def test_base_chain_crossval_fit_and_predict():
    # Fit chain with cross_val_predict and verify predict
    # performance
    X, Y = generate_multilabel_dataset_with_correlations()

    for chain in [ClassifierChain(LogisticRegression()), RegressorChain(Ridge())]:
        chain.fit(X, Y)
        chain_cv = clone(chain).set_params(cv=3)
        chain_cv.fit(X, Y)
        Y_pred_cv = chain_cv.predict(X)
        Y_pred = chain.predict(X)

        assert Y_pred_cv.shape == Y_pred.shape
        assert not np.all(Y_pred == Y_pred_cv)
        if isinstance(chain, ClassifierChain):
            assert jaccard_similarity_score(Y, Y_pred_cv, average="samples") > 0.4
        else:
            assert mean_squared_error(Y, Y_pred_cv) < 0.25
//  [python]
def test_base_chain_crossval_fit_and_predict():
    # Fit chain with cross_val_predict and verify predict
    # performance
    X, Y = generate_multilabel_dataset_with_correlations()

    for chain in [ClassifierChain(LogisticRegression()), RegressorChain(Ridge())]:
        chain.fit(X, Y)
        chain_cv = clone(chain).set_params(cv=3)
        chain_cv.fit(X, Y)
        Y_pred_cv = chain_cv.predict(X)
        Y_pred = chain.predict(X)

        assert Y_pred_cv.shape == Y_pred.shape
        assert not np.all(Y_pred == Y_pred_cv)
        if isinstance(chain, ClassifierChain):
            assert jaccard_score(Y, Y_pred_cv, average="samples") > 0.4
        else:
            assert mean_squared_error(Y, Y_pred_cv) < 0.25
//  [python]
plt.show()

predicted_score = np.zeros((9025,1))

for i in range(0,9025,1):
  if(predicted[i,0] == 1):
    predicted_score[i] = 1

  elif(predicted[i,1] == 1):
    predicted_score[i] = 2

  elif(predicted[i,2] == 1):
    predicted_score[i] = 3

  else:
    predicted_score[i] =0

print('f1.score-',sklearn.metrics.f1_score(gt_score, predicted_score, average='weighted'))
print('jaccard score-',sklearn.metrics.jaccard_similarity_score(gt_score.ravel(), predicted_score.ravel()))
//  [python]
plt.show()

predicted_score = np.zeros((9025,1))

for i in range(0,9025,1):
  if(predicted[i,0] == 1):
    predicted_score[i] = 1

  elif(predicted[i,1] == 1):
    predicted_score[i] = 2

  elif(predicted[i,2] == 1):
    predicted_score[i] = 3

  else:
    predicted_score[i] =0

print('f1.score-',sklearn.metrics.f1_score(gt_score, predicted_score, average='weighted'))
print('jaccard score-',sklearn.metrics.jaccard_score(gt_score, predicted_score, average='weighted'))
//  [python]
def eval_2D_Material_Seg(pred_file, gt_file):
    """
    Evaluation function for 2D material tagging

    Args:
      pred_file: a txt file, each line contains shape_id, pred_cls for all pixels.
      gt_file: a txt file, each line contains shape_id, gt_cls for all pixels..
    """
    preds = np.loadtxt(pred_file)
    gts = np.loadtxt(gt_file)
    assert len(preds) == len(gts)

    y_true = gts[:,1:]
    y_pred = preds[:,1:]

    f1 = metrics.f1_score(y_true, y_pred)
    prec = metrics.average_precision_score(y_true, y_pred)

    mIoU = metrics.jaccard_similarity_score(y_true, y_pred, average='macro')

    return f1, prec, mIoU
//  [python]
def eval_2D_Material_Seg(pred_file, gt_file):
    """
    Evaluation function for 2D material tagging

    Args:
      pred_file: a txt file, each line contains shape_id, pred_cls for all pixels.
      gt_file: a txt file, each line contains shape_id, gt_cls for all pixels..
    """
    preds = np.loadtxt(pred_file)
    gts = np.loadtxt(gt_file)
    assert len(preds) == len(gts)

    y_true = gts[:,1:]
    y_pred = preds[:,1:]

    f1 = metrics.f1_score(y_true, y_pred)
    prec = metrics.average_precision_score(y_true, y_pred)

    mIoU = metrics.jaccard_score(y_true, y_pred, average='macro')

    return f1, prec, mIoU
//  [python]
def eval_3D_Material_Seg(pred_file, gt_file):
    """
    Evaluation function for 3D shape classification

    Args:
      pred_file: a txt file, each line contains shape_id, pred_cls for all points.
      gt_file: a txt file, each line contains shape_id, gt_cls for all points.
    """
    preds = np.loadtxt(pred_file)
    gts = np.loadtxt(gt_file)
    assert len(preds) == len(gts)

    y_true = gts[:,1:]
    y_pred = preds[:,1:]

    f1 = metrics.f1_score(y_true, y_pred)
    prec = metrics.average_precision_score(y_true, y_pred)
    mIoU = metrics.jaccard_similarity_score(y_true, y_pred, average='macro')

    return f1, prec, mIoU
//  [python]
def eval_3D_Material_Seg(pred_file, gt_file):
    """
    Evaluation function for 3D shape classification

    Args:
      pred_file: a txt file, each line contains shape_id, pred_cls for all points.
      gt_file: a txt file, each line contains shape_id, gt_cls for all points.
    """
    preds = np.loadtxt(pred_file)
    gts = np.loadtxt(gt_file)
    assert len(preds) == len(gts)

    y_true = gts[:,1:]
    y_pred = preds[:,1:]

    f1 = metrics.f1_score(y_true, y_pred)
    prec = metrics.average_precision_score(y_true, y_pred)
    mIoU = metrics.jaccard_score(y_true, y_pred, average='macro')

    return f1, prec, mIoU
//  [python]
def compute_jaccard_score(true_targets, predictions, per_sample=False, average='macro'):
    if per_sample:
        jaccard = metrics.jaccard_similarity_score(true_targets, predictions, average=None)
    else:
        if average not in set(['samples', 'macro', 'weighted']):
            raise ValueError("Specify samples or macro")
        jaccard = metrics.jaccard_similarity_score(true_targets, predictions, average=average)
    return jaccard
//  [python]
def compute_jaccard_score(true_targets, predictions, per_sample=False, average='macro'):
    if per_sample:
        jaccard = metrics.jaccard_score(true_targets, predictions, average=None)
    else:
        if average not in set(['samples', 'macro', 'weighted']):
            raise ValueError("Specify samples or macro")
        jaccard = metrics.jaccard_score(true_targets, predictions, average=average)
    return jaccard
//  [python]
def jaccard(y_true, y_pred, **args):
    """Jaccard score based on the `sklearn.metrics.jaccard_score`_ function.

    More details here : `Jaccard similarity coefficient score`_

    .. _sklearn.metrics.jaccard_score: https://scikit-learn.org/stable/modules/generated/sklearn.metrics.jaccard_score.html#sklearn.metrics.jaccard_score
    .. _Jaccard similarity coefficient score: https://scikit-learn.org/stable/modules/model_evaluation.html#jaccard-similarity-score
    """
    return s.jaccard_score(y_true, y_pred, **args)
//  [python]
def jaccard(y_true, y_pred, **args):
    """Jaccard score based on the `sklearn.metrics.jaccard_score`_ function.

    More details here : `Jaccard similarity coefficient score`_

    .. _sklearn.metrics.jaccard_score: https://scikit-learn.org/stable/modules/generated/sklearn.metrics.jaccard_score.html#sklearn.metrics.jaccard_score
    .. _Jaccard similarity coefficient score: https://scikit-learn.org/stable/modules/model_evaluation.html#jaccard-similarity-score
    """
    return sklearn.metrics.jaccard_score(y_true, y_pred, **args)
//  [python]
def jaccard_score(y_true: np.ndarray, y_pred: np.ndarray, **kwargs) -> float:
    return metrics.jaccard_similarity_score(y_true, y_pred, **kwargs)
//  [python]
def jaccard_score(y_true: np.ndarray, y_pred: np.ndarray, **kwargs) -> float:
    return metrics.jaccard_score(y_true, y_pred, **kwargs)
//  [python]
def test_binary_jaccard_reference(real_cm, real_truth_binary_values, real_prediction_binary_values):
    value = metrics.binary_jaccard(real_cm)
    reference_value = sklearn.metrics.jaccard_similarity_score(
        real_truth_binary_values, real_prediction_binary_values
    )

    assert value == pytest.approx(reference_value)
//  [python]
def test_binary_jaccard_reference(real_cm, real_truth_binary_values, real_prediction_binary_values):
    value = metrics.binary_jaccard(real_cm)
    reference_value = sklearn.metrics.jaccard_score(
        real_truth_binary_values, real_prediction_binary_values
    )

    assert value == pytest.approx(reference_value)
//  [python]
def jaccard(
    y_true: np.ndarray,
    y_score: np.ndarray,
    threshold: float = 0.5,
) -> float:
    """Compute the Jaccard score for the given true and predicted labels.

    Parameters
    ----------
    y_true
        True labels.
    y_score
        An array of predicted probabilities for each class.
    threshold
        The threshold to use for converting probabilities to binary
        predictions, by default 0.5.

    Returns
    -------
    float
        The Jaccard score.

    Notes
    -----
    This function is a wrapper around `sklearn.metrics.jaccard_score` that
    computes the Jaccard score for each sample and then averages over the
    samples.

    Note also that the y_score input is assumed to be an array of probabilities
    for each class. This function will convert the probabilities to binary
    predictions using the given threshold.
    """

    if y_true.ndim == 1:
        y_true = y_true[np.newaxis, :]

    if y_score.ndim == 1:
        y_score = y_score[np.newaxis, :]

    labels = np.arange(y_true.shape[1])

    return metrics.jaccard_similarity_score(
        y_true=y_true,
        y_pred=y_score > threshold,
        labels=labels,
        average="samples",
    )
//  [python]
def jaccard(
    y_true: np.ndarray,
    y_score: np.ndarray,
    threshold: float = 0.5,
) -> float:
    """Compute the Jaccard score for the given true and predicted labels.

    Parameters
    ----------
    y_true
        True labels.
    y_score
        An array of predicted probabilities for each class.
    threshold
        The threshold to use for converting probabilities to binary
        predictions, by default 0.5.

    Returns
    -------
    float
        The Jaccard score.

    Notes
    -----
    This function is a wrapper around `sklearn.metrics.jaccard_score` that
    computes the Jaccard score for each sample and then averages over the
    samples.

    Note also that the y_score input is assumed to be an array of probabilities
    for each class. This function will convert the probabilities to binary
    predictions using the given threshold.
    """

    if y_true.ndim == 1:
        y_true = y_true[np.newaxis, :]

    if y_score.ndim == 1:
        y_score = y_score[np.newaxis, :]

    labels = np.arange(y_true.shape[1])

    return metrics.jaccard_score(
        y_true=y_true,
        y_pred=y_score > threshold,
        labels=labels,
        average="samples",
    )
//  [python]
def calculate_metrics(features, predicted_labels, true_labels, epoch, batch, ds):
    
    k = len(np.unique(predicted_labels))
    distances = pairwise_distances(features)

    results = defaultdict(list)
    results['homogeneity_score'].append(metrics.homogeneity_score(true_labels, predicted_labels))
    results['completeness_score'].append(metrics.completeness_score(true_labels, predicted_labels))
    results['v_measure_score'].append(metrics.v_measure_score(true_labels, predicted_labels))
    results['adjusted_rand_score'].append(metrics.adjusted_rand_score(true_labels, predicted_labels))
    results['adjusted_mutual_info_score'].append(metrics.adjusted_mutual_info_score(true_labels, predicted_labels))
    results['average_jaccard_score'].append(np.mean(metrics.jaccard_similarity_score(true_labels.reshape(-1,1), predicted_labels.reshape(-1,1), average=None)))
    results['dunn_index'].append(dunn(distances, predicted_labels))
    if len(np.unique(predicted_labels)) == 1 or k == len(features):
        results['silhouette_score'].append(-1)
    else:
        results['silhouette_score'].append(metrics.silhouette_score(features, predicted_labels, metric='sqeuclidean'))
    
    if ds == 'test':
        latex_table = pd.DataFrame.from_dict(results).to_latex(index=False, float_format="%.3f").replace('\\toprule', '\\hline').replace('\\midrule', '\\hline').replace('\\bottomrule','\\hline')
        with open(f"./logs/tables/cluster_metrics_epoch_{epoch}_batch_{batch}.tex", "w") as writer:
            writer.write(latex_table)
    else:
        print(pd.DataFrame.from_dict(results))
//  [python]
def calculate_metrics(features, predicted_labels, true_labels, epoch, batch, ds):
    
    k = len(np.unique(predicted_labels))
    distances = pairwise_distances(features)

    results = defaultdict(list)
    results['homogeneity_score'].append(metrics.homogeneity_score(true_labels, predicted_labels))
    results['completeness_score'].append(metrics.completeness_score(true_labels, predicted_labels))
    results['v_measure_score'].append(metrics.v_measure_score(true_labels, predicted_labels))
    results['adjusted_rand_score'].append(metrics.adjusted_rand_score(true_labels, predicted_labels))
    results['adjusted_mutual_info_score'].append(metrics.adjusted_mutual_info_score(true_labels, predicted_labels))
    results['average_jaccard_score'].append(np.mean(metrics.jaccard_score(true_labels, predicted_labels, average=None)))
    results['dunn_index'].append(dunn(distances, predicted_labels))
    if len(np.unique(predicted_labels)) == 1 or k == len(features):
        results['silhouette_score'].append(-1)
    else:
        results['silhouette_score'].append(metrics.silhouette_score(features, predicted_labels, metric='sqeuclidean'))
    
    if ds == 'test':
        latex_table = pd.DataFrame.from_dict(results).to_latex(index=False, float_format="%.3f").replace('\\toprule', '\\hline').replace('\\midrule', '\\hline').replace('\\bottomrule','\\hline')
        with open(f"./logs/tables/cluster_metrics_epoch_{epoch}_batch_{batch}.tex", "w") as writer:
            writer.write(latex_table)
    else:
        print(pd.DataFrame.from_dict(results))
//  [python]
def evaluate_srnpdj(gt, pred, K=25):
    """
    Parameters:
        gt: np.array([N, ...])
            ground truth array of binary labels (integers)
        pred: np.array([, ...])
            same shape as ground truth
    Returns:
        srnpdj_N6: np.array(shape=[N, 6])
            for each paired item in (gt, pred), reteurn 5 evaluation numberse:
            specificity, recall, npv, ppv (prcision), dice-sim, jaccard.
        idx_low_metric_dict: dict(str: [int])
            dictionary of indices with lowest specificities, recall, npv, ppv, and dicesim
    """

    dicesim = []
    jaccard = []
    specificity = []
    recall = []
    negativepv = []
    precision = []

    for _y_true, _y_pred in zip(gt, pred):
        _y_true, _y_pred = _y_true.flatten(), _y_pred.flatten()
        srnp = get_srnp(_y_true, _y_pred)
        specificity.append(srnp['specificity'])
        recall.append(srnp['recall'])
        negativepv.append(srnp['negativepv'])
        precision.append(srnp['precision'])

        dicesim.append(1. - distance.dice(_y_true, _y_pred))
        jaccard.append(sklearn.metrics.jaccard_similarity_score(_y_true, _y_pred))

    specificity = np.array(specificity)
    recall = np.array(recall)
    negativepv = np.array(negativepv)
    precision = np.array(precision)
    dicesim = np.array(dicesim)
    jaccard = np.array(jaccard)
    logging.info("dicesim shape: {}".format(repr(dicesim.shape)))

    lowest_specificity = specificity.argsort()[:K]
    lowest_recall = recall.argsort()[:K]
    lowest_npv = negativepv.argsort()[:K]
    lowest_ppv = precision.argsort()[:K]
    lowest_dicesim = dicesim.argsort()[:K]
    lowest_jaccard = jaccard.argsort()[:K]

    srnpdj_N6 = np.stack([specificity, recall, negativepv, precision, dicesim, jaccard], axis=1)

    idx_low_metric_dict = {
        'specificity': lowest_specificity,
        'recall': lowest_recall,
        'npv': lowest_npv,
        'ppv': lowest_ppv,
        'dicesim': lowest_dicesim,
        'jaccard': lowest_jaccard,
    }
    return srnpdj_N6, idx_low_metric_dict
//  [python]
def evaluate_srnpdj(gt, pred, K=25):
    """
    Parameters:
        gt: np.array([N, ...])
            ground truth array of binary labels (integers)
        pred: np.array([, ...])
            same shape as ground truth
    Returns:
        srnpdj_N6: np.array(shape=[N, 6])
            for each paired item in (gt, pred), reteurn 5 evaluation numberse:
            specificity, recall, npv, ppv (prcision), dice-sim, jaccard.
        idx_low_metric_dict: dict(str: [int])
            dictionary of indices with lowest specificities, recall, npv, ppv, and dicesim
    """

    dicesim = []
    jaccard = []
    specificity = []
    recall = []
    negativepv = []
    precision = []

    for _y_true, _y_pred in zip(gt, pred):
        _y_true, _y_pred = _y_true.flatten(), _y_pred.flatten()
        srnp = get_srnp(_y_true, _y_pred)
        specificity.append(srnp['specificity'])
        recall.append(srnp['recall'])
        negativepv.append(srnp['negativepv'])
        precision.append(srnp['precision'])

        dicesim.append(1. - distance.dice(_y_true, _y_pred))
        jaccard.append(sklearn.metrics.jaccard_score(_y_true, _y_pred))

    specificity = np.array(specificity)
    recall = np.array(recall)
    negativepv = np.array(negativepv)
    precision = np.array(precision)
    dicesim = np.array(dicesim)
    jaccard = np.array(jaccard)
    logging.info("dicesim shape: {}".format(repr(dicesim.shape)))

    lowest_specificity = specificity.argsort()[:K]
    lowest_recall = recall.argsort()[:K]
    lowest_npv = negativepv.argsort()[:K]
    lowest_ppv = precision.argsort()[:K]
    lowest_dicesim = dicesim.argsort()[:K]
    lowest_jaccard = jaccard.argsort()[:K]

    srnpdj_N6 = np.stack([specificity, recall, negativepv, precision, dicesim, jaccard], axis=1)

    idx_low_metric_dict = {
        'specificity': lowest_specificity,
        'recall': lowest_recall,
        'npv': lowest_npv,
        'ppv': lowest_ppv,
        'dicesim': lowest_dicesim,
        'jaccard': lowest_jaccard,
    }
    return srnpdj_N6, idx_low_metric_dict
//  [python]
def evaluate(self):
        jaccard_score = sklearn.metrics.jaccard_similarity_score(self.answer_prompt, self.chatgpt_prompt, average='macro')
        bleu_score = self.bleu(self.answer_prompt, self.chatgpt_prompt)
        rouge_score = self.rouge_n(self.answer_prompt, self.chatgpt_prompt)
        ter_score = self.ter(self.answer_prompt, self.chatgpt_prompt)
        print("Jaccard score: ", jaccard_score)
        print("BLEU score: ", bleu_score)
        print("Rouge score: ",rouge_score)
        print("TER score: ", ter_score)
//  [python]
def evaluate(self):
        jaccard_score = sklearn.metrics.jaccard_score(self.answer_prompt, self.chatgpt_prompt, average='macro')
        bleu_score = self.bleu(self.answer_prompt, self.chatgpt_prompt)
        rouge_score = self.rouge_n(self.answer_prompt, self.chatgpt_prompt)
        ter_score = self.ter(self.answer_prompt, self.chatgpt_prompt)
        print("Jaccard score: ", jaccard_score)
        print("BLEU score: ", bleu_score)
        print("Rouge score: ",rouge_score)
        print("TER score: ", ter_score)
//  [python]
def single_target_metrics(targets, scores):
    """generate various metrics for a set of scores and labels (targets)

    Predicts 1 for the highest scoring class per sample and 0 for
    all other classes.

    Args:
        targets: 0/1 lables in 2d array
        scores: continuous values in 2d array

    Returns:
        metrics_dict: dictionary of various overall and per-class metrics

    """
    if max(np.sum(targets, 1)) > 1:
        raise ValueError(
            "Labels were not single target! "
            "Use multi-target classifier if multiple classes can be present "
            "in a single sample."
        )

    metrics_dict = {}

    preds = predict_single_target_labels(scores=scores)

    # Confusion matrix requires numbered-class not one-hot labels
    t = np.argmax(targets, 1)
    p = np.argmax(preds, 1)
    metrics_dict["confusion_matrix"] = M.confusion_matrix(t, p)

    # precision, recall, and f1
    pre, rec, f1, _ = M.precision_recall_fscore_support(
        targets, preds, average=None, zero_division=0
    )
    metrics_dict.update({"precision": pre[1], "recall": rec[1], "f1": f1[1]})

    try:
        metrics_dict["jaccard"] = s.jaccard_similarity_score(targets, preds, average="macro")
    except ValueError:
        metrics_dict["jaccard"] = np.nan
    try:
        metrics_dict["hamming_loss"] = M.hamming_loss(targets, preds)
    except ValueError:
        metrics_dict["hamming_loss"] = np.nan

    return metrics_dict
//  [python]
def single_target_metrics(targets, scores):
    """generate various metrics for a set of scores and labels (targets)

    Predicts 1 for the highest scoring class per sample and 0 for
    all other classes.

    Args:
        targets: 0/1 lables in 2d array
        scores: continuous values in 2d array

    Returns:
        metrics_dict: dictionary of various overall and per-class metrics

    """
    if max(np.sum(targets, 1)) > 1:
        raise ValueError(
            "Labels were not single target! "
            "Use multi-target classifier if multiple classes can be present "
            "in a single sample."
        )

    metrics_dict = {}

    preds = predict_single_target_labels(scores=scores)

    # Confusion matrix requires numbered-class not one-hot labels
    t = np.argmax(targets, 1)
    p = np.argmax(preds, 1)
    metrics_dict["confusion_matrix"] = M.confusion_matrix(t, p)

    # precision, recall, and f1
    pre, rec, f1, _ = M.precision_recall_fscore_support(
        targets, preds, average=None, zero_division=0
    )
    metrics_dict.update({"precision": pre[1], "recall": rec[1], "f1": f1[1]})

    try:
        metrics_dict["jaccard"] = M.jaccard_score(targets, preds, average="macro")
    except ValueError:
        metrics_dict["jaccard"] = np.nan
    try:
        metrics_dict["hamming_loss"] = M.hamming_loss(targets, preds)
    except ValueError:
        metrics_dict["hamming_loss"] = np.nan

    return metrics_dict
//  [python]
def evaluate(pred, gt):
    pred = np.round(pred).astype(int).flatten()
    gt = gt.flatten()

    fmes = sklearn.metrics.f1_score(gt, pred)
    acc = sklearn.metrics.accuracy_score(gt, pred)
    rec = sklearn.metrics.recall_score(gt, pred)
    jacc = 1 - sklearn.metrics.zero_one_loss(gt, pred)
    TP, FP, TN, FN = perf_measure(gt, pred)
    return fmes, acc, rec, jacc, TP, FP, TN, FN
//  [python]
def evaluate(pred, gt):
    pred = np.round(pred).astype(int).flatten()
    gt = gt.flatten()

    fmes = sklearn.metrics.f1_score(gt, pred)
    acc = sklearn.metrics.accuracy_score(gt, pred)
    rec = sklearn.metrics.recall_score(gt, pred)
    jacc = sklearn.metrics.jaccard_score(gt, pred)
    TP, FP, TN, FN = perf_measure(gt, pred)
    return fmes, acc, rec, jacc, TP, FP, TN, FN
//  [python]
def on_epoch_end(self, batch, logs=None):
        self.epoch += 1
        self.keras_metric.reset_state()
        predictions = self.model.predict(self.x_test)
        jaccard_value = jaccard_similarity_score(
            np.argmax(predictions, axis=-1), self.y_test, average=None
        )
        self.keras_metric.update_state(jaccard_value)
        self._write_metric(
            self.keras_metric.name, self.keras_metric.result().numpy().astype(float)
        )
//  [python]
def on_epoch_end(self, batch, logs=None):
        self.epoch += 1
        self.keras_metric.reset_state()
        predictions = self.model.predict(self.x_test)
        jaccard_value = jaccard_score(
            np.argmax(predictions, axis=-1), self.y_test, average=None
        )
        self.keras_metric.update_state(jaccard_value)
        self._write_metric(
            self.keras_metric.name, self.keras_metric.result().numpy().astype(float)
        )
//  [python]
def compute(self, data_dict):
        data = data_dict["data"]
        preds = data_dict["predict"]
        args = {}
        y_data = data.y

        warnings.filterwarnings("ignore")
        self.metrics["accuracy"].value = sklearn.metrics.accuracy_score(y_data, preds, **args.get("accuracy", {}))
        self.metrics["balanced_accuracy"].value = sklearn.metrics.balanced_accuracy_score(y_data, preds, **args.get("balanced_accuracy", {}))
        self.metrics["confusion_matrix"].value = sklearn.metrics.confusion_matrix(y_data, preds, **args.get("confusion_matrix", {}))
        fptn = get_fptn(self.metrics["confusion_matrix"].value)  # TP, TN, FP, FN values. Used quite a bit.

        self.metrics["fp_rate"].value = _fp_rate(fptn, **args.get("fp_rate", {}))
        self.metrics["fp_rate_avg"].value = np.mean(self.metrics["fp_rate"].value)

        self.metrics["f1"].value = sklearn.metrics.f1_score(y_data, preds, average=None, **args.get("f1", {}))
        self.metrics["f1_avg"].value = np.mean(self.metrics["f1"].value)

        self.metrics["jaccard_score"].value = np.nan_to_num(sklearn.metrics.jaccard_similarity_score(
            y_data, preds, average=None, **args.get("jaccard_score", {})), nan=0
        )
        self.metrics["jaccard_score_avg"].value = np.mean(self.metrics["jaccard_score"].value)

        self.metrics["precision_score"].value = sklearn.metrics.precision_score(y_data, preds, average=None)
        self.metrics["precision_score_avg"].value = np.mean(self.metrics["precision_score"].value)

        self.metrics["recall_score"].value = np.nan_to_num(_recall_score(fptn, **args.get("recall_score", {})), nan=0)
        self.metrics["recall_score_avg"].value = np.mean(self.metrics["recall_score"].value)
//  [python]
def compute(self, data_dict):
        data = data_dict["data"]
        preds = data_dict["predict"]
        args = {}
        y_data = data.y

        warnings.filterwarnings("ignore")
        self.metrics["accuracy"].value = sklearn.metrics.accuracy_score(y_data, preds, **args.get("accuracy", {}))
        self.metrics["balanced_accuracy"].value = sklearn.metrics.balanced_accuracy_score(y_data, preds, **args.get("balanced_accuracy", {}))
        self.metrics["confusion_matrix"].value = sklearn.metrics.confusion_matrix(y_data, preds, **args.get("confusion_matrix", {}))
        fptn = get_fptn(self.metrics["confusion_matrix"].value)  # TP, TN, FP, FN values. Used quite a bit.

        self.metrics["fp_rate"].value = _fp_rate(fptn, **args.get("fp_rate", {}))
        self.metrics["fp_rate_avg"].value = np.mean(self.metrics["fp_rate"].value)

        self.metrics["f1"].value = sklearn.metrics.f1_score(y_data, preds, average=None, **args.get("f1", {}))
        self.metrics["f1_avg"].value = np.mean(self.metrics["f1"].value)

        self.metrics["jaccard_score"].value = np.nan_to_num(sklearn.metrics.jaccard_score(
            y_data, preds, average=None, **args.get("jaccard_score", {})), nan=0
        )
        self.metrics["jaccard_score_avg"].value = np.mean(self.metrics["jaccard_score"].value)

        self.metrics["precision_score"].value = sklearn.metrics.precision_score(y_data, preds, average=None)
        self.metrics["precision_score_avg"].value = np.mean(self.metrics["precision_score"].value)

        self.metrics["recall_score"].value = np.nan_to_num(_recall_score(fptn, **args.get("recall_score", {})), nan=0)
        self.metrics["recall_score_avg"].value = np.mean(self.metrics["recall_score"].value)
//  [python]
def stats(self):
		print('Accuracy: %.5f' % skm.accuracy_score(self.actual, self.predicted))
		#print('Balanced Accuracy: %.5f' % skm.balanced_accuracy_score(self.actual, self.predicted))
		print('F1: %.5f' % skm.f1_score(self.actual, self.predicted, average='weighted'))
		print('Recall: %.5f' % skm.recall_score(self.actual, self.predicted, average='weighted'))
		print('Precision: %.5f' % skm.precision_score(self.actual, self.predicted, average='weighted'))
		print('Jaccard: %.5f' % skm.jaccard_similarity_score(self.actual, self.predicted))
//  [python]
def stats(self):
		print('Accuracy: %.5f' % skm.accuracy_score(self.actual, self.predicted))
		#print('Balanced Accuracy: %.5f' % skm.balanced_accuracy_score(self.actual, self.predicted))
		print('F1: %.5f' % skm.f1_score(self.actual, self.predicted, average='weighted'))
		print('Recall: %.5f' % skm.recall_score(self.actual, self.predicted, average='weighted'))
		print('Precision: %.5f' % skm.precision_score(self.actual, self.predicted, average='weighted'))
		print('Jaccard: %.5f' % skm.jaccard_score(self.actual, self.predicted, average='weighted'))