/
error_test.py
73 lines (73 loc) · 3.12 KB
/
error_test.py
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
# -*- coding: utf-8 -*-
"""
>>> from pycm import *
>>> import os
>>> import json
>>> y_actu = [2, 0, 2, 2, 0, 1, 1, 2, 2, 0, 1, 2]
>>> cm_2 = ConfusionMatrix(y_actu, 2)
Traceback (most recent call last):
...
pycm.pycm_obj.pycmVectorError: The type of input vectors is assumed to be a list or a NumPy array
>>> cm_3 = ConfusionMatrix(y_actu, [1,2])
Traceback (most recent call last):
...
pycm.pycm_obj.pycmVectorError: Input vectors must have same length
>>> cm_4 = ConfusionMatrix([], [])
Traceback (most recent call last):
...
pycm.pycm_obj.pycmVectorError: Input vectors are empty
>>> cm_5 = ConfusionMatrix([1,1,1,], [1,1,1,1])
Traceback (most recent call last):
...
pycm.pycm_obj.pycmVectorError: Input vectors must have same length
>>> cm3=ConfusionMatrix(matrix={})
Traceback (most recent call last):
...
pycm.pycm_obj.pycmMatrixError: Input confusion matrix format error
>>> cm_4=ConfusionMatrix(matrix={1:{1:2,"1":2},"1":{1:2,"1":3}})
Traceback (most recent call last):
...
pycm.pycm_obj.pycmMatrixError: Type of the input matrix classes is assumed be the same
>>> cm_5=ConfusionMatrix(matrix={1:{1:2}})
Traceback (most recent call last):
...
pycm.pycm_obj.pycmVectorError: Number of the classes is lower than 2
>>> y_actu = [2, 0, 2, 2, 0, 1, 1, 2, 2, 0, 1, 2]
>>> y_pred = [0, 0, 2, 1, 0, 2, 1, 0, 2, 0, 2, 2]
>>> cm = ConfusionMatrix(y_actu,y_pred)
>>> cm.relabel([1,2,3])
Traceback (most recent call last):
...
pycm.pycm_obj.pycmMatrixError: Mapping format error
>>> cm.relabel({1:"L1",2:"L2"})
Traceback (most recent call last):
...
pycm.pycm_obj.pycmMatrixError: Mapping class names error
>>> cp = Compare([cm,cm])
Traceback (most recent call last):
...
pycm.pycm_obj.pycmCompareError: The input type is considered to be dictionary but it's not!
>>> cp = Compare({"cm1":cm})
Traceback (most recent call last):
...
pycm.pycm_obj.pycmCompareError: Lower than two confusion matrices is given for comparing. The minimum number of confusion matrix for comparing is 2.
>>> cp = Compare({"cm1":cm,"cm2":[]})
Traceback (most recent call last):
...
pycm.pycm_obj.pycmCompareError: The input is considered to consist of pycm.ConfusionMatrix object but it's not!
>>> cm2 = ConfusionMatrix(matrix={"Class1":{"Class1":9,"Class2":3,"Class3":0},"Class2":{"Class1":3,"Class2":5,"Class3":1},"Class3":{"Class1":1,"Class2":1,"Class3":4}})
>>> cp = Compare({"cm1":cm,"cm2":cm2})
Traceback (most recent call last):
...
pycm.pycm_obj.pycmCompareError: The domain of all ConfusionMatrix objects must be same! The sample size or the number of classes are different.
>>> y_pred = [0, 0, 2, 1, 0, 2, 1, 0, 2, 0, 2, 1]
>>> cm3 = ConfusionMatrix(y_actu,y_pred)
>>> cp = Compare({"cm1":cm,"cm2":cm3},by_class=True,weight={1:1,2:1})
Traceback (most recent call last):
...
pycm.pycm_obj.pycmCompareError: The weight type must be dictionary and also must be set for all classes.
>>> cp = Compare({"cm1":cm,"cm2":cm3},by_class=True,weight=[])
Traceback (most recent call last):
...
pycm.pycm_obj.pycmCompareError: The weight type must be dictionary and also must be set for all classes.
"""