File: 01-basic.t

package info (click to toggle)
libstatistics-contingency-perl 0.09-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 124 kB
  • sloc: perl: 153; makefile: 2
file content (83 lines) | stat: -rw-r--r-- 2,348 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.pl'

#########################

use strict;
use Test;
BEGIN { plan tests => 24 };

use Statistics::Contingency;

ok(1);

my $all_categories = [qw(sports politics finance world)];

{
  my $e = new Statistics::Contingency(categories => $all_categories);
  ok $e;
  
  $e->add_result(['sports','finance'], ['sports']);
  ok $e->micro_recall, 1, "micro recall";
  ok $e->micro_precision, 0.5, "micro precision";
  ok $e->micro_F1, 2/3, "micro F1";
}

{
  my $e = new Statistics::Contingency(categories => $all_categories);
  $e->add_result(['sports','finance'], ['politics']);
  ok $e->micro_recall, 0, "micro recall";
  ok $e->micro_precision, 0, "micro precision";
  ok $e->micro_F1, 0, "micro F1";
}

{
  my $e = new Statistics::Contingency(categories => $all_categories);
  
  $e->add_result(['sports','finance'], ['sports']);
  ok $e->micro_recall, 1, "micro recall";
  ok $e->macro_recall, 1, "macro recall";

  $e->add_result(['sports','finance'], ['politics']);

  ok $e->micro_recall, 0.5, "micro recall";
  ok $e->micro_precision, 0.25, "micro precision";
  ok $e->micro_F1, 1/3, "micro F1";

  ok $e->macro_recall, 0.75, "macro recall";
  ok $e->macro_precision, 0.375, "macro precision";
  ok $e->macro_F1, 5/12, "macro F1";
}

{
  my $e = new Statistics::Contingency(categories => $all_categories);
  $e->add_result([], ['politics']);
  ok $e->micro_recall, 0, "micro recall";
  ok $e->micro_precision, 0, "micro precision";
  ok $e->micro_F1, 0, "micro F1";
}

{
  my $e = new Statistics::Contingency(categories => $all_categories);
  $e->add_result([], []);
  ok $e->micro_recall, 1, "micro recall";
  ok $e->micro_precision, 1, "micro precision";
  ok $e->micro_F1, 1, "micro F1";
}

{
  my $e = new Statistics::Contingency(categories => $all_categories);
  $e->add_result(['sports','finance'], ['sports']);
  print $e->stats_table;

  $e = new Statistics::Contingency(categories => $all_categories);
  $e->add_result(['sports','finance'], ['politics']);
  print $e->stats_table;
}

{
  my $e = new Statistics::Contingency(categories => $all_categories);
  $e->set_entries(2, 3, 5, 19);
  ok $e->micro_precision, 2/(2+3), "micro precision\n";
  ok $e->micro_recall,    2/(2+5), "micro recall\n";
}