confusion_matrix 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.rdoc +22 -22
  3. data/README.rdoc +88 -88
  4. data/lib/confusion_matrix.rb +383 -451
  5. data/test/matrix_test.rb +160 -160
  6. metadata +10 -15
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bc3f9ed40d45bb892541c4a3dc97c04c5893e335ec79b2526d072d291d08a7b7
4
- data.tar.gz: 602f9857a4e45283357117974943d46f4802fbd9c5ce7b1be0ec704472d29ba4
3
+ metadata.gz: 7c054f9ff8a3aed4fc0cef535cb2506aec2d1928ac5b944ec1d6687f6691fce1
4
+ data.tar.gz: 56a11a2175d65f9a54dc8041f7b7f974abb6e63b3d201b6ed9d81f76b6957765
5
5
  SHA512:
6
- metadata.gz: 20cc86e92c2ad0867206ee2c2a46fe31de7c08c15e90491d481a8c40fd94541b4dea87b575792652cedbb49fea284e70e4f72250ab6f2e83de2e9b57ea7136c6
7
- data.tar.gz: 972386c261254d2fc44b09f320d48b41639c09682f16c0ddeb88cd2697b683f7b178d257e7edcb3bcba51d0dfc4c625bf478fcadd1a6e2e81ed8354a588266ce
6
+ metadata.gz: 9003d2e3f983cf3403680384ea1addc416e518afec979f3def0913ad60d51b760627eaefd8d52459723683042fc3cf57b120e624c95d023e0e87dbb2022f7ad6
7
+ data.tar.gz: 8c218ba99d31d456934fbbb0ae866b703503388f3a668f4d89eb2f05a380bda77f820c0b4b08e253f8ae6eca4e16e7857f6735717d9c06cd0a5ec29dd4ca49d8
data/LICENSE.rdoc CHANGED
@@ -1,22 +1,22 @@
1
- = MIT License
2
-
3
- Copyright (c) 2020-23, Peter Lane
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
22
-
1
+ = MIT License
2
+
3
+ Copyright (c) 2020-23, Peter Lane
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.rdoc CHANGED
@@ -1,88 +1,88 @@
1
- = Confusion Matrix
2
-
3
- Install from {RubyGems}[https://rubygems.org/gems/confusion_matrix/]:
4
-
5
- > gem install confusion_matrix
6
-
7
- source:: https://notabug.org/peterlane/confusion-matrix-ruby/
8
-
9
- == Description
10
-
11
- A confusion matrix is used in data-mining as a summary of the performance of a
12
- classification algorithm. Each row represents the _actual_ class of an
13
- instance, and each column represents the _predicted_ class of that instance,
14
- i.e. the class that they were classified as. Numbers at each (row, column)
15
- reflect the total number of instances of actual class "row" which were
16
- predicted to fall in class "column".
17
-
18
- A two-class example is:
19
-
20
- Classified Classified |
21
- Positive Negative | Actual
22
- ------------------------------+------------
23
- a b | Positive
24
- c d | Negative
25
-
26
- Here the value:
27
-
28
- a:: is the number of true positives (those labelled positive and classified positive)
29
- b:: is the number of false negatives (those labelled positive but classified negative)
30
- c:: is the number of false positives (those labelled negative but classified positive)
31
- d:: is the number of true negatives (those labelled negative and classified negative)
32
-
33
- From this table we can calculate statistics like:
34
-
35
- true_positive_rate:: a/(a+b)
36
- positive recall:: a/(a+c)
37
-
38
- The implementation supports confusion matrices with more than two
39
- classes, and hence most statistics are calculated with reference to a
40
- named class. When more than two classes are in use, the statistics
41
- are calculated as if the named class were positive and all the other
42
- classes are grouped as if negative.
43
-
44
- For example, in a three-class example:
45
-
46
- Classified Classified Classified |
47
- Red Blue Green | Actual
48
- --------------------------------------------+------------
49
- a b c | Red
50
- d e f | Blue
51
- g h i | Green
52
-
53
- We can calculate:
54
-
55
- true_red_rate:: a/(a+b+c)
56
- red recall:: a/(a+d+g)
57
-
58
- == Example
59
-
60
- The following example creates a simple two-class confusion matrix,
61
- prints a few statistics and displays the table.
62
-
63
- require 'confusion_matrix'
64
-
65
- cm = ConfusionMatrix.new :pos, :neg
66
- cm.add_for(:pos, :pos, 10)
67
- 3.times { cm.add_for(:pos, :neg) }
68
- 20.times { cm.add_for(:neg, :neg) }
69
- 5.times { cm.add_for(:neg, :pos) }
70
-
71
- puts "Precision: #{cm.precision}"
72
- puts "Recall: #{cm.recall}"
73
- puts "MCC: #{cm.matthews_correlation}"
74
- puts
75
- puts(cm.to_s)
76
-
77
- Output:
78
-
79
- Precision: 0.6666666666666666
80
- Recall: 0.7692307692307693
81
- MCC: 0.5524850114241865
82
-
83
- Predicted |
84
- pos neg | Actual
85
- ----------+-------
86
- 10 3 | pos
87
- 5 20 | neg
88
-
1
+ = Confusion Matrix
2
+
3
+ Available from:
4
+ - RubyGems: https://rubygems.org/gems/confusion_matrix/
5
+ - Source: https://codeberg.org/peterlane/confusion-matrix/
6
+
7
+ == Description
8
+
9
+ A confusion matrix represents "the relative frequencies with which each of a
10
+ number of stimuli is mistaken for each of the others by a person in a task
11
+ requiring recognition or identification of stimuli" (R. Colman,
12
+ <i>A Dictionary of Psychology</i>, 2008). Each row represents the predicted label of an instance, and
13
+ each column represents the observed label of that instance. Numbers at each
14
+ (row, column) reflect the total number of instances of predicted label "row"
15
+ which were observed as having label "column".
16
+
17
+ A two-label example is:
18
+
19
+ Observed Observed |
20
+ Positive Negative | Predicted
21
+ ------------------------------+------------
22
+ a b | Positive
23
+ c d | Negative
24
+
25
+ Here the value:
26
+
27
+ a:: is the number of true positives (those predicted positive and observed positive)
28
+ b:: is the number of false negatives (those predicted positive but observed negative)
29
+ c:: is the number of false positives (those predicted negative but observed positive)
30
+ d:: is the number of true negatives (those predicted negative and observed negative)
31
+
32
+ From this matrix we can calculate statistics like:
33
+
34
+ true positive rate:: a/(a+b)
35
+ positive recall:: a/(a+c)
36
+
37
+ The implementation supports confusion matrices with more than two
38
+ labels, and hence most statistics are calculated with reference to a
39
+ named label. When more than two labels are in use, the statistics
40
+ are calculated as if the named label were positive and all the other
41
+ labels are grouped as if negative.
42
+
43
+ For example, in a three-label example:
44
+
45
+ Observed Observed Observed |
46
+ Red Blue Green | Predicted
47
+ --------------------------------------------+------------
48
+ a b c | Red
49
+ d e f | Blue
50
+ g h i | Green
51
+
52
+ We can calculate:
53
+
54
+ true red rate:: a/(a+b+c)
55
+ red recall:: a/(a+d+g)
56
+
57
+ == Example
58
+
59
+ The following example creates a two-label confusion matrix,
60
+ prints a few statistics and displays the matrix as a table.
61
+
62
+ require 'confusion_matrix'
63
+
64
+ cm = ConfusionMatrix.new :pos, :neg
65
+ cm.add_for(:pos, :pos, 10)
66
+ 3.times { cm.add_for(:pos, :neg) }
67
+ 20.times { cm.add_for(:neg, :neg) }
68
+ 5.times { cm.add_for(:neg, :pos) }
69
+
70
+ puts "Precision: #{cm.precision}"
71
+ puts "Recall: #{cm.recall}"
72
+ puts "MCC: #{cm.matthews_correlation}"
73
+ puts
74
+ puts(cm.to_s)
75
+
76
+ Output:
77
+
78
+ Precision: 0.6666666666666666
79
+ Recall: 0.7692307692307693
80
+ MCC: 0.5524850114241865
81
+
82
+ Observed |
83
+ pos neg | Predicted
84
+ ---------+----------
85
+ 10 3 | pos
86
+ 5 20 | neg
87
+
88
+