id
int32 0
252k
| repo
stringlengths 7
55
| path
stringlengths 4
127
| func_name
stringlengths 1
88
| original_string
stringlengths 75
19.8k
| language
stringclasses 1
value | code
stringlengths 75
19.8k
| code_tokens
list | docstring
stringlengths 3
17.3k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 87
242
|
|---|---|---|---|---|---|---|---|---|---|---|---|
236,200
|
trailofbits/protofuzz
|
protofuzz/protofuzz.py
|
descriptor_to_generator
|
def descriptor_to_generator(cls_descriptor, cls, limit=0):
'Convert a protobuf descriptor to a protofuzz generator for same type'
generators = []
for descriptor in cls_descriptor.fields_by_name.values():
generator = _prototype_to_generator(descriptor, cls)
if limit != 0:
generator.set_limit(limit)
generators.append(generator)
obj = cls(cls_descriptor.name, *generators)
return obj
|
python
|
def descriptor_to_generator(cls_descriptor, cls, limit=0):
'Convert a protobuf descriptor to a protofuzz generator for same type'
generators = []
for descriptor in cls_descriptor.fields_by_name.values():
generator = _prototype_to_generator(descriptor, cls)
if limit != 0:
generator.set_limit(limit)
generators.append(generator)
obj = cls(cls_descriptor.name, *generators)
return obj
|
[
"def",
"descriptor_to_generator",
"(",
"cls_descriptor",
",",
"cls",
",",
"limit",
"=",
"0",
")",
":",
"generators",
"=",
"[",
"]",
"for",
"descriptor",
"in",
"cls_descriptor",
".",
"fields_by_name",
".",
"values",
"(",
")",
":",
"generator",
"=",
"_prototype_to_generator",
"(",
"descriptor",
",",
"cls",
")",
"if",
"limit",
"!=",
"0",
":",
"generator",
".",
"set_limit",
"(",
"limit",
")",
"generators",
".",
"append",
"(",
"generator",
")",
"obj",
"=",
"cls",
"(",
"cls_descriptor",
".",
"name",
",",
"*",
"generators",
")",
"return",
"obj"
] |
Convert a protobuf descriptor to a protofuzz generator for same type
|
[
"Convert",
"a",
"protobuf",
"descriptor",
"to",
"a",
"protofuzz",
"generator",
"for",
"same",
"type"
] |
589492d34de9a0da6cc5554094e2588b893b2fd8
|
https://github.com/trailofbits/protofuzz/blob/589492d34de9a0da6cc5554094e2588b893b2fd8/protofuzz/protofuzz.py#L108-L121
|
236,201
|
trailofbits/protofuzz
|
protofuzz/protofuzz.py
|
_assign_to_field
|
def _assign_to_field(obj, name, val):
'Helper to assign an arbitrary value to a protobuf field'
target = getattr(obj, name)
if isinstance(target, containers.RepeatedScalarFieldContainer):
target.append(val)
elif isinstance(target, containers.RepeatedCompositeFieldContainer):
target = target.add()
target.CopyFrom(val)
elif isinstance(target, (int, float, bool, str, bytes)):
setattr(obj, name, val)
elif isinstance(target, message.Message):
target.CopyFrom(val)
else:
raise RuntimeError("Unsupported type: {}".format(type(target)))
|
python
|
def _assign_to_field(obj, name, val):
'Helper to assign an arbitrary value to a protobuf field'
target = getattr(obj, name)
if isinstance(target, containers.RepeatedScalarFieldContainer):
target.append(val)
elif isinstance(target, containers.RepeatedCompositeFieldContainer):
target = target.add()
target.CopyFrom(val)
elif isinstance(target, (int, float, bool, str, bytes)):
setattr(obj, name, val)
elif isinstance(target, message.Message):
target.CopyFrom(val)
else:
raise RuntimeError("Unsupported type: {}".format(type(target)))
|
[
"def",
"_assign_to_field",
"(",
"obj",
",",
"name",
",",
"val",
")",
":",
"target",
"=",
"getattr",
"(",
"obj",
",",
"name",
")",
"if",
"isinstance",
"(",
"target",
",",
"containers",
".",
"RepeatedScalarFieldContainer",
")",
":",
"target",
".",
"append",
"(",
"val",
")",
"elif",
"isinstance",
"(",
"target",
",",
"containers",
".",
"RepeatedCompositeFieldContainer",
")",
":",
"target",
"=",
"target",
".",
"add",
"(",
")",
"target",
".",
"CopyFrom",
"(",
"val",
")",
"elif",
"isinstance",
"(",
"target",
",",
"(",
"int",
",",
"float",
",",
"bool",
",",
"str",
",",
"bytes",
")",
")",
":",
"setattr",
"(",
"obj",
",",
"name",
",",
"val",
")",
"elif",
"isinstance",
"(",
"target",
",",
"message",
".",
"Message",
")",
":",
"target",
".",
"CopyFrom",
"(",
"val",
")",
"else",
":",
"raise",
"RuntimeError",
"(",
"\"Unsupported type: {}\"",
".",
"format",
"(",
"type",
"(",
"target",
")",
")",
")"
] |
Helper to assign an arbitrary value to a protobuf field
|
[
"Helper",
"to",
"assign",
"an",
"arbitrary",
"value",
"to",
"a",
"protobuf",
"field"
] |
589492d34de9a0da6cc5554094e2588b893b2fd8
|
https://github.com/trailofbits/protofuzz/blob/589492d34de9a0da6cc5554094e2588b893b2fd8/protofuzz/protofuzz.py#L124-L138
|
236,202
|
trailofbits/protofuzz
|
protofuzz/protofuzz.py
|
_fields_to_object
|
def _fields_to_object(descriptor, fields):
'Helper to convert a descriptor and a set of fields to a Protobuf instance'
# pylint: disable=protected-access
obj = descriptor._concrete_class()
for name, value in fields:
if isinstance(value, tuple):
subtype = descriptor.fields_by_name[name].message_type
value = _fields_to_object(subtype, value)
_assign_to_field(obj, name, value)
return obj
|
python
|
def _fields_to_object(descriptor, fields):
'Helper to convert a descriptor and a set of fields to a Protobuf instance'
# pylint: disable=protected-access
obj = descriptor._concrete_class()
for name, value in fields:
if isinstance(value, tuple):
subtype = descriptor.fields_by_name[name].message_type
value = _fields_to_object(subtype, value)
_assign_to_field(obj, name, value)
return obj
|
[
"def",
"_fields_to_object",
"(",
"descriptor",
",",
"fields",
")",
":",
"# pylint: disable=protected-access",
"obj",
"=",
"descriptor",
".",
"_concrete_class",
"(",
")",
"for",
"name",
",",
"value",
"in",
"fields",
":",
"if",
"isinstance",
"(",
"value",
",",
"tuple",
")",
":",
"subtype",
"=",
"descriptor",
".",
"fields_by_name",
"[",
"name",
"]",
".",
"message_type",
"value",
"=",
"_fields_to_object",
"(",
"subtype",
",",
"value",
")",
"_assign_to_field",
"(",
"obj",
",",
"name",
",",
"value",
")",
"return",
"obj"
] |
Helper to convert a descriptor and a set of fields to a Protobuf instance
|
[
"Helper",
"to",
"convert",
"a",
"descriptor",
"and",
"a",
"set",
"of",
"fields",
"to",
"a",
"Protobuf",
"instance"
] |
589492d34de9a0da6cc5554094e2588b893b2fd8
|
https://github.com/trailofbits/protofuzz/blob/589492d34de9a0da6cc5554094e2588b893b2fd8/protofuzz/protofuzz.py#L141-L152
|
236,203
|
trailofbits/protofuzz
|
protofuzz/protofuzz.py
|
_module_to_generators
|
def _module_to_generators(pb_module):
'''
Convert a protobuf module to a dict of generators.
This is typically used with modules that contain multiple type definitions.
'''
if not pb_module:
return None
message_types = pb_module.DESCRIPTOR.message_types_by_name
return {k: ProtobufGenerator(v) for k, v in message_types.items()}
|
python
|
def _module_to_generators(pb_module):
'''
Convert a protobuf module to a dict of generators.
This is typically used with modules that contain multiple type definitions.
'''
if not pb_module:
return None
message_types = pb_module.DESCRIPTOR.message_types_by_name
return {k: ProtobufGenerator(v) for k, v in message_types.items()}
|
[
"def",
"_module_to_generators",
"(",
"pb_module",
")",
":",
"if",
"not",
"pb_module",
":",
"return",
"None",
"message_types",
"=",
"pb_module",
".",
"DESCRIPTOR",
".",
"message_types_by_name",
"return",
"{",
"k",
":",
"ProtobufGenerator",
"(",
"v",
")",
"for",
"k",
",",
"v",
"in",
"message_types",
".",
"items",
"(",
")",
"}"
] |
Convert a protobuf module to a dict of generators.
This is typically used with modules that contain multiple type definitions.
|
[
"Convert",
"a",
"protobuf",
"module",
"to",
"a",
"dict",
"of",
"generators",
"."
] |
589492d34de9a0da6cc5554094e2588b893b2fd8
|
https://github.com/trailofbits/protofuzz/blob/589492d34de9a0da6cc5554094e2588b893b2fd8/protofuzz/protofuzz.py#L224-L233
|
236,204
|
trailofbits/protofuzz
|
protofuzz/protofuzz.py
|
ProtobufGenerator.add_dependency
|
def add_dependency(self, source, target, action):
'''
Create a dependency between fields source and target via callable
action.
>>> permuter = protofuzz.from_description_string("""
... message Address {
... required uint32 one = 1;
... required uint32 two = 2;
... }""")['Address']
>>> permuter.add_dependency('one', 'two', lambda val: max(0,val-1))
>>> for obj in permuter.linear():
... print("obj = {}".format(obj))
...
obj = one: 0
two: 1
obj = one: 256
two: 257
obj = one: 4096
two: 4097
obj = one: 1073741823
two: 1073741824
'''
self._dependencies.append((source, target, action))
|
python
|
def add_dependency(self, source, target, action):
'''
Create a dependency between fields source and target via callable
action.
>>> permuter = protofuzz.from_description_string("""
... message Address {
... required uint32 one = 1;
... required uint32 two = 2;
... }""")['Address']
>>> permuter.add_dependency('one', 'two', lambda val: max(0,val-1))
>>> for obj in permuter.linear():
... print("obj = {}".format(obj))
...
obj = one: 0
two: 1
obj = one: 256
two: 257
obj = one: 4096
two: 4097
obj = one: 1073741823
two: 1073741824
'''
self._dependencies.append((source, target, action))
|
[
"def",
"add_dependency",
"(",
"self",
",",
"source",
",",
"target",
",",
"action",
")",
":",
"self",
".",
"_dependencies",
".",
"append",
"(",
"(",
"source",
",",
"target",
",",
"action",
")",
")"
] |
Create a dependency between fields source and target via callable
action.
>>> permuter = protofuzz.from_description_string("""
... message Address {
... required uint32 one = 1;
... required uint32 two = 2;
... }""")['Address']
>>> permuter.add_dependency('one', 'two', lambda val: max(0,val-1))
>>> for obj in permuter.linear():
... print("obj = {}".format(obj))
...
obj = one: 0
two: 1
obj = one: 256
two: 257
obj = one: 4096
two: 4097
obj = one: 1073741823
two: 1073741824
|
[
"Create",
"a",
"dependency",
"between",
"fields",
"source",
"and",
"target",
"via",
"callable",
"action",
"."
] |
589492d34de9a0da6cc5554094e2588b893b2fd8
|
https://github.com/trailofbits/protofuzz/blob/589492d34de9a0da6cc5554094e2588b893b2fd8/protofuzz/protofuzz.py#L185-L213
|
236,205
|
sepandhaghighi/pycm
|
pycm/pycm_compare.py
|
Compare.print_report
|
def print_report(self):
"""
Print Compare report.
:return: None
"""
report = compare_report_print(
self.sorted, self.scores, self.best_name)
print(report)
|
python
|
def print_report(self):
"""
Print Compare report.
:return: None
"""
report = compare_report_print(
self.sorted, self.scores, self.best_name)
print(report)
|
[
"def",
"print_report",
"(",
"self",
")",
":",
"report",
"=",
"compare_report_print",
"(",
"self",
".",
"sorted",
",",
"self",
".",
"scores",
",",
"self",
".",
"best_name",
")",
"print",
"(",
"report",
")"
] |
Print Compare report.
:return: None
|
[
"Print",
"Compare",
"report",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_compare.py#L98-L106
|
236,206
|
sepandhaghighi/pycm
|
pycm/pycm_class_func.py
|
F_calc
|
def F_calc(TP, FP, FN, beta):
"""
Calculate F-score.
:param TP: true positive
:type TP : int
:param FP: false positive
:type FP : int
:param FN: false negative
:type FN : int
:param beta : beta coefficient
:type beta : float
:return: F score as float
"""
try:
result = ((1 + (beta)**2) * TP) / \
((1 + (beta)**2) * TP + FP + (beta**2) * FN)
return result
except ZeroDivisionError:
return "None"
|
python
|
def F_calc(TP, FP, FN, beta):
"""
Calculate F-score.
:param TP: true positive
:type TP : int
:param FP: false positive
:type FP : int
:param FN: false negative
:type FN : int
:param beta : beta coefficient
:type beta : float
:return: F score as float
"""
try:
result = ((1 + (beta)**2) * TP) / \
((1 + (beta)**2) * TP + FP + (beta**2) * FN)
return result
except ZeroDivisionError:
return "None"
|
[
"def",
"F_calc",
"(",
"TP",
",",
"FP",
",",
"FN",
",",
"beta",
")",
":",
"try",
":",
"result",
"=",
"(",
"(",
"1",
"+",
"(",
"beta",
")",
"**",
"2",
")",
"*",
"TP",
")",
"/",
"(",
"(",
"1",
"+",
"(",
"beta",
")",
"**",
"2",
")",
"*",
"TP",
"+",
"FP",
"+",
"(",
"beta",
"**",
"2",
")",
"*",
"FN",
")",
"return",
"result",
"except",
"ZeroDivisionError",
":",
"return",
"\"None\""
] |
Calculate F-score.
:param TP: true positive
:type TP : int
:param FP: false positive
:type FP : int
:param FN: false negative
:type FN : int
:param beta : beta coefficient
:type beta : float
:return: F score as float
|
[
"Calculate",
"F",
"-",
"score",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_class_func.py#L61-L80
|
236,207
|
sepandhaghighi/pycm
|
pycm/pycm_class_func.py
|
G_calc
|
def G_calc(item1, item2):
"""
Calculate G-measure & G-mean.
:param item1: PPV or TPR or TNR
:type item1 : float
:param item2: PPV or TPR or TNR
:type item2 : float
:return: G-measure or G-mean as float
"""
try:
result = math.sqrt(item1 * item2)
return result
except Exception:
return "None"
|
python
|
def G_calc(item1, item2):
"""
Calculate G-measure & G-mean.
:param item1: PPV or TPR or TNR
:type item1 : float
:param item2: PPV or TPR or TNR
:type item2 : float
:return: G-measure or G-mean as float
"""
try:
result = math.sqrt(item1 * item2)
return result
except Exception:
return "None"
|
[
"def",
"G_calc",
"(",
"item1",
",",
"item2",
")",
":",
"try",
":",
"result",
"=",
"math",
".",
"sqrt",
"(",
"item1",
"*",
"item2",
")",
"return",
"result",
"except",
"Exception",
":",
"return",
"\"None\""
] |
Calculate G-measure & G-mean.
:param item1: PPV or TPR or TNR
:type item1 : float
:param item2: PPV or TPR or TNR
:type item2 : float
:return: G-measure or G-mean as float
|
[
"Calculate",
"G",
"-",
"measure",
"&",
"G",
"-",
"mean",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_class_func.py#L156-L170
|
236,208
|
sepandhaghighi/pycm
|
pycm/pycm_class_func.py
|
RACC_calc
|
def RACC_calc(TOP, P, POP):
"""
Calculate random accuracy.
:param TOP: test outcome positive
:type TOP : int
:param P: condition positive
:type P : int
:param POP: population
:type POP:int
:return: RACC as float
"""
try:
result = (TOP * P) / ((POP) ** 2)
return result
except Exception:
return "None"
|
python
|
def RACC_calc(TOP, P, POP):
"""
Calculate random accuracy.
:param TOP: test outcome positive
:type TOP : int
:param P: condition positive
:type P : int
:param POP: population
:type POP:int
:return: RACC as float
"""
try:
result = (TOP * P) / ((POP) ** 2)
return result
except Exception:
return "None"
|
[
"def",
"RACC_calc",
"(",
"TOP",
",",
"P",
",",
"POP",
")",
":",
"try",
":",
"result",
"=",
"(",
"TOP",
"*",
"P",
")",
"/",
"(",
"(",
"POP",
")",
"**",
"2",
")",
"return",
"result",
"except",
"Exception",
":",
"return",
"\"None\""
] |
Calculate random accuracy.
:param TOP: test outcome positive
:type TOP : int
:param P: condition positive
:type P : int
:param POP: population
:type POP:int
:return: RACC as float
|
[
"Calculate",
"random",
"accuracy",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_class_func.py#L173-L189
|
236,209
|
sepandhaghighi/pycm
|
pycm/pycm_class_func.py
|
CEN_misclassification_calc
|
def CEN_misclassification_calc(
table,
TOP,
P,
i,
j,
subject_class,
modified=False):
"""
Calculate misclassification probability of classifying.
:param table: input matrix
:type table : dict
:param TOP: test outcome positive
:type TOP : int
:param P: condition positive
:type P : int
:param i: table row index (class name)
:type i : any valid type
:param j: table col index (class name)
:type j : any valid type
:param subject_class: subject to class (class name)
:type subject_class: any valid type
:param modified : modified mode flag
:type modified : bool
:return: misclassification probability of classifying as float
"""
try:
result = TOP + P
if modified:
result -= table[subject_class][subject_class]
result = table[i][j] / result
return result
except Exception:
return "None"
|
python
|
def CEN_misclassification_calc(
table,
TOP,
P,
i,
j,
subject_class,
modified=False):
"""
Calculate misclassification probability of classifying.
:param table: input matrix
:type table : dict
:param TOP: test outcome positive
:type TOP : int
:param P: condition positive
:type P : int
:param i: table row index (class name)
:type i : any valid type
:param j: table col index (class name)
:type j : any valid type
:param subject_class: subject to class (class name)
:type subject_class: any valid type
:param modified : modified mode flag
:type modified : bool
:return: misclassification probability of classifying as float
"""
try:
result = TOP + P
if modified:
result -= table[subject_class][subject_class]
result = table[i][j] / result
return result
except Exception:
return "None"
|
[
"def",
"CEN_misclassification_calc",
"(",
"table",
",",
"TOP",
",",
"P",
",",
"i",
",",
"j",
",",
"subject_class",
",",
"modified",
"=",
"False",
")",
":",
"try",
":",
"result",
"=",
"TOP",
"+",
"P",
"if",
"modified",
":",
"result",
"-=",
"table",
"[",
"subject_class",
"]",
"[",
"subject_class",
"]",
"result",
"=",
"table",
"[",
"i",
"]",
"[",
"j",
"]",
"/",
"result",
"return",
"result",
"except",
"Exception",
":",
"return",
"\"None\""
] |
Calculate misclassification probability of classifying.
:param table: input matrix
:type table : dict
:param TOP: test outcome positive
:type TOP : int
:param P: condition positive
:type P : int
:param i: table row index (class name)
:type i : any valid type
:param j: table col index (class name)
:type j : any valid type
:param subject_class: subject to class (class name)
:type subject_class: any valid type
:param modified : modified mode flag
:type modified : bool
:return: misclassification probability of classifying as float
|
[
"Calculate",
"misclassification",
"probability",
"of",
"classifying",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_class_func.py#L265-L299
|
236,210
|
sepandhaghighi/pycm
|
pycm/pycm_output.py
|
html_init
|
def html_init(name):
"""
Return HTML report file first lines.
:param name: name of file
:type name : str
:return: html_init as str
"""
result = ""
result += "<html>\n"
result += "<head>\n"
result += "<title>" + str(name) + "</title>\n"
result += "</head>\n"
result += "<body>\n"
result += '<h1 style="border-bottom:1px solid ' \
'black;text-align:center;">PyCM Report</h1>'
return result
|
python
|
def html_init(name):
"""
Return HTML report file first lines.
:param name: name of file
:type name : str
:return: html_init as str
"""
result = ""
result += "<html>\n"
result += "<head>\n"
result += "<title>" + str(name) + "</title>\n"
result += "</head>\n"
result += "<body>\n"
result += '<h1 style="border-bottom:1px solid ' \
'black;text-align:center;">PyCM Report</h1>'
return result
|
[
"def",
"html_init",
"(",
"name",
")",
":",
"result",
"=",
"\"\"",
"result",
"+=",
"\"<html>\\n\"",
"result",
"+=",
"\"<head>\\n\"",
"result",
"+=",
"\"<title>\"",
"+",
"str",
"(",
"name",
")",
"+",
"\"</title>\\n\"",
"result",
"+=",
"\"</head>\\n\"",
"result",
"+=",
"\"<body>\\n\"",
"result",
"+=",
"'<h1 style=\"border-bottom:1px solid '",
"'black;text-align:center;\">PyCM Report</h1>'",
"return",
"result"
] |
Return HTML report file first lines.
:param name: name of file
:type name : str
:return: html_init as str
|
[
"Return",
"HTML",
"report",
"file",
"first",
"lines",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_output.py#L10-L26
|
236,211
|
sepandhaghighi/pycm
|
pycm/pycm_output.py
|
html_dataset_type
|
def html_dataset_type(is_binary, is_imbalanced):
"""
Return HTML report file dataset type.
:param is_binary: is_binary flag (binary : True , multi-class : False)
:type is_binary: bool
:param is_imbalanced: is_imbalanced flag (imbalance : True , balance : False)
:type is_imbalanced: bool
:return: dataset_type as str
"""
result = "<h2>Dataset Type : </h2>\n"
balance_type = "Balanced"
class_type = "Binary Classification"
if is_imbalanced:
balance_type = "Imbalanced"
if not is_binary:
class_type = "Multi-Class Classification"
result += "<ul>\n\n<li>{0}</li>\n\n<li>{1}</li>\n</ul>\n".format(
class_type, balance_type)
result += "<p>{0}</p>\n".format(RECOMMEND_HTML_MESSAGE)
result += "<p>{0}</p>\n".format(RECOMMEND_HTML_MESSAGE2)
return result
|
python
|
def html_dataset_type(is_binary, is_imbalanced):
"""
Return HTML report file dataset type.
:param is_binary: is_binary flag (binary : True , multi-class : False)
:type is_binary: bool
:param is_imbalanced: is_imbalanced flag (imbalance : True , balance : False)
:type is_imbalanced: bool
:return: dataset_type as str
"""
result = "<h2>Dataset Type : </h2>\n"
balance_type = "Balanced"
class_type = "Binary Classification"
if is_imbalanced:
balance_type = "Imbalanced"
if not is_binary:
class_type = "Multi-Class Classification"
result += "<ul>\n\n<li>{0}</li>\n\n<li>{1}</li>\n</ul>\n".format(
class_type, balance_type)
result += "<p>{0}</p>\n".format(RECOMMEND_HTML_MESSAGE)
result += "<p>{0}</p>\n".format(RECOMMEND_HTML_MESSAGE2)
return result
|
[
"def",
"html_dataset_type",
"(",
"is_binary",
",",
"is_imbalanced",
")",
":",
"result",
"=",
"\"<h2>Dataset Type : </h2>\\n\"",
"balance_type",
"=",
"\"Balanced\"",
"class_type",
"=",
"\"Binary Classification\"",
"if",
"is_imbalanced",
":",
"balance_type",
"=",
"\"Imbalanced\"",
"if",
"not",
"is_binary",
":",
"class_type",
"=",
"\"Multi-Class Classification\"",
"result",
"+=",
"\"<ul>\\n\\n<li>{0}</li>\\n\\n<li>{1}</li>\\n</ul>\\n\"",
".",
"format",
"(",
"class_type",
",",
"balance_type",
")",
"result",
"+=",
"\"<p>{0}</p>\\n\"",
".",
"format",
"(",
"RECOMMEND_HTML_MESSAGE",
")",
"result",
"+=",
"\"<p>{0}</p>\\n\"",
".",
"format",
"(",
"RECOMMEND_HTML_MESSAGE2",
")",
"return",
"result"
] |
Return HTML report file dataset type.
:param is_binary: is_binary flag (binary : True , multi-class : False)
:type is_binary: bool
:param is_imbalanced: is_imbalanced flag (imbalance : True , balance : False)
:type is_imbalanced: bool
:return: dataset_type as str
|
[
"Return",
"HTML",
"report",
"file",
"dataset",
"type",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_output.py#L29-L51
|
236,212
|
sepandhaghighi/pycm
|
pycm/pycm_output.py
|
color_check
|
def color_check(color):
"""
Check input color format.
:param color: input color
:type color : tuple
:return: color as list
"""
if isinstance(color, (tuple, list)):
if all(map(lambda x: isinstance(x, int), color)):
if all(map(lambda x: x < 256, color)):
return list(color)
if isinstance(color, str):
color_lower = color.lower()
if color_lower in TABLE_COLOR.keys():
return TABLE_COLOR[color_lower]
return [0, 0, 0]
|
python
|
def color_check(color):
"""
Check input color format.
:param color: input color
:type color : tuple
:return: color as list
"""
if isinstance(color, (tuple, list)):
if all(map(lambda x: isinstance(x, int), color)):
if all(map(lambda x: x < 256, color)):
return list(color)
if isinstance(color, str):
color_lower = color.lower()
if color_lower in TABLE_COLOR.keys():
return TABLE_COLOR[color_lower]
return [0, 0, 0]
|
[
"def",
"color_check",
"(",
"color",
")",
":",
"if",
"isinstance",
"(",
"color",
",",
"(",
"tuple",
",",
"list",
")",
")",
":",
"if",
"all",
"(",
"map",
"(",
"lambda",
"x",
":",
"isinstance",
"(",
"x",
",",
"int",
")",
",",
"color",
")",
")",
":",
"if",
"all",
"(",
"map",
"(",
"lambda",
"x",
":",
"x",
"<",
"256",
",",
"color",
")",
")",
":",
"return",
"list",
"(",
"color",
")",
"if",
"isinstance",
"(",
"color",
",",
"str",
")",
":",
"color_lower",
"=",
"color",
".",
"lower",
"(",
")",
"if",
"color_lower",
"in",
"TABLE_COLOR",
".",
"keys",
"(",
")",
":",
"return",
"TABLE_COLOR",
"[",
"color_lower",
"]",
"return",
"[",
"0",
",",
"0",
",",
"0",
"]"
] |
Check input color format.
:param color: input color
:type color : tuple
:return: color as list
|
[
"Check",
"input",
"color",
"format",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_output.py#L54-L70
|
236,213
|
sepandhaghighi/pycm
|
pycm/pycm_output.py
|
html_table_color
|
def html_table_color(row, item, color=(0, 0, 0)):
"""
Return background color of each cell of table.
:param row: row dictionary
:type row : dict
:param item: cell number
:type item : int
:param color : input color
:type color : tuple
:return: background color as list [R,G,B]
"""
result = [0, 0, 0]
color_list = color_check(color)
max_color = max(color_list)
back_color_index = 255 - int((item / (sum(list(row.values())) + 1)) * 255)
for i in range(3):
result[i] = back_color_index - (max_color - color_list[i])
if result[i] < 0:
result[i] = 0
return result
|
python
|
def html_table_color(row, item, color=(0, 0, 0)):
"""
Return background color of each cell of table.
:param row: row dictionary
:type row : dict
:param item: cell number
:type item : int
:param color : input color
:type color : tuple
:return: background color as list [R,G,B]
"""
result = [0, 0, 0]
color_list = color_check(color)
max_color = max(color_list)
back_color_index = 255 - int((item / (sum(list(row.values())) + 1)) * 255)
for i in range(3):
result[i] = back_color_index - (max_color - color_list[i])
if result[i] < 0:
result[i] = 0
return result
|
[
"def",
"html_table_color",
"(",
"row",
",",
"item",
",",
"color",
"=",
"(",
"0",
",",
"0",
",",
"0",
")",
")",
":",
"result",
"=",
"[",
"0",
",",
"0",
",",
"0",
"]",
"color_list",
"=",
"color_check",
"(",
"color",
")",
"max_color",
"=",
"max",
"(",
"color_list",
")",
"back_color_index",
"=",
"255",
"-",
"int",
"(",
"(",
"item",
"/",
"(",
"sum",
"(",
"list",
"(",
"row",
".",
"values",
"(",
")",
")",
")",
"+",
"1",
")",
")",
"*",
"255",
")",
"for",
"i",
"in",
"range",
"(",
"3",
")",
":",
"result",
"[",
"i",
"]",
"=",
"back_color_index",
"-",
"(",
"max_color",
"-",
"color_list",
"[",
"i",
"]",
")",
"if",
"result",
"[",
"i",
"]",
"<",
"0",
":",
"result",
"[",
"i",
"]",
"=",
"0",
"return",
"result"
] |
Return background color of each cell of table.
:param row: row dictionary
:type row : dict
:param item: cell number
:type item : int
:param color : input color
:type color : tuple
:return: background color as list [R,G,B]
|
[
"Return",
"background",
"color",
"of",
"each",
"cell",
"of",
"table",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_output.py#L73-L93
|
236,214
|
sepandhaghighi/pycm
|
pycm/pycm_output.py
|
html_table
|
def html_table(classes, table, rgb_color, normalize=False):
"""
Return HTML report file confusion matrix.
:param classes: matrix classes
:type classes: list
:param table: matrix
:type table : dict
:param rgb_color : input color
:type rgb_color : tuple
:param normalize : save normalize matrix flag
:type normalize : bool
:return: html_table as str
"""
result = ""
result += "<h2>Confusion Matrix "
if normalize:
result += "(Normalized)"
result += ": </h2>\n"
result += '<table>\n'
result += '<tr align="center">' + "\n"
result += '<td>Actual</td>\n'
result += '<td>Predict\n'
table_size = str((len(classes) + 1) * 7) + "em"
result += '<table style="border:1px solid black;border-collapse: collapse;height:{0};width:{0};">\n'\
.format(table_size)
classes.sort()
result += '<tr align="center">\n<td></td>\n'
part_2 = ""
for i in classes:
class_name = str(i)
if len(class_name) > 6:
class_name = class_name[:4] + "..."
result += '<td style="border:1px solid ' \
'black;padding:10px;height:7em;width:7em;">' + \
class_name + '</td>\n'
part_2 += '<tr align="center">\n'
part_2 += '<td style="border:1px solid ' \
'black;padding:10px;height:7em;width:7em;">' + \
class_name + '</td>\n'
for j in classes:
item = table[i][j]
color = "black;"
back_color = html_table_color(table[i], item, rgb_color)
if min(back_color) < 128:
color = "white"
part_2 += '<td style="background-color: rgb({0},{1},{2});color:{3};padding:10px;height:7em;width:7em;">'.format(
str(back_color[0]), str(back_color[1]), str(back_color[2]), color) + str(item) + '</td>\n'
part_2 += "</tr>\n"
result += '</tr>\n'
part_2 += "</table>\n</td>\n</tr>\n</table>\n"
result += part_2
return result
|
python
|
def html_table(classes, table, rgb_color, normalize=False):
"""
Return HTML report file confusion matrix.
:param classes: matrix classes
:type classes: list
:param table: matrix
:type table : dict
:param rgb_color : input color
:type rgb_color : tuple
:param normalize : save normalize matrix flag
:type normalize : bool
:return: html_table as str
"""
result = ""
result += "<h2>Confusion Matrix "
if normalize:
result += "(Normalized)"
result += ": </h2>\n"
result += '<table>\n'
result += '<tr align="center">' + "\n"
result += '<td>Actual</td>\n'
result += '<td>Predict\n'
table_size = str((len(classes) + 1) * 7) + "em"
result += '<table style="border:1px solid black;border-collapse: collapse;height:{0};width:{0};">\n'\
.format(table_size)
classes.sort()
result += '<tr align="center">\n<td></td>\n'
part_2 = ""
for i in classes:
class_name = str(i)
if len(class_name) > 6:
class_name = class_name[:4] + "..."
result += '<td style="border:1px solid ' \
'black;padding:10px;height:7em;width:7em;">' + \
class_name + '</td>\n'
part_2 += '<tr align="center">\n'
part_2 += '<td style="border:1px solid ' \
'black;padding:10px;height:7em;width:7em;">' + \
class_name + '</td>\n'
for j in classes:
item = table[i][j]
color = "black;"
back_color = html_table_color(table[i], item, rgb_color)
if min(back_color) < 128:
color = "white"
part_2 += '<td style="background-color: rgb({0},{1},{2});color:{3};padding:10px;height:7em;width:7em;">'.format(
str(back_color[0]), str(back_color[1]), str(back_color[2]), color) + str(item) + '</td>\n'
part_2 += "</tr>\n"
result += '</tr>\n'
part_2 += "</table>\n</td>\n</tr>\n</table>\n"
result += part_2
return result
|
[
"def",
"html_table",
"(",
"classes",
",",
"table",
",",
"rgb_color",
",",
"normalize",
"=",
"False",
")",
":",
"result",
"=",
"\"\"",
"result",
"+=",
"\"<h2>Confusion Matrix \"",
"if",
"normalize",
":",
"result",
"+=",
"\"(Normalized)\"",
"result",
"+=",
"\": </h2>\\n\"",
"result",
"+=",
"'<table>\\n'",
"result",
"+=",
"'<tr align=\"center\">'",
"+",
"\"\\n\"",
"result",
"+=",
"'<td>Actual</td>\\n'",
"result",
"+=",
"'<td>Predict\\n'",
"table_size",
"=",
"str",
"(",
"(",
"len",
"(",
"classes",
")",
"+",
"1",
")",
"*",
"7",
")",
"+",
"\"em\"",
"result",
"+=",
"'<table style=\"border:1px solid black;border-collapse: collapse;height:{0};width:{0};\">\\n'",
".",
"format",
"(",
"table_size",
")",
"classes",
".",
"sort",
"(",
")",
"result",
"+=",
"'<tr align=\"center\">\\n<td></td>\\n'",
"part_2",
"=",
"\"\"",
"for",
"i",
"in",
"classes",
":",
"class_name",
"=",
"str",
"(",
"i",
")",
"if",
"len",
"(",
"class_name",
")",
">",
"6",
":",
"class_name",
"=",
"class_name",
"[",
":",
"4",
"]",
"+",
"\"...\"",
"result",
"+=",
"'<td style=\"border:1px solid '",
"'black;padding:10px;height:7em;width:7em;\">'",
"+",
"class_name",
"+",
"'</td>\\n'",
"part_2",
"+=",
"'<tr align=\"center\">\\n'",
"part_2",
"+=",
"'<td style=\"border:1px solid '",
"'black;padding:10px;height:7em;width:7em;\">'",
"+",
"class_name",
"+",
"'</td>\\n'",
"for",
"j",
"in",
"classes",
":",
"item",
"=",
"table",
"[",
"i",
"]",
"[",
"j",
"]",
"color",
"=",
"\"black;\"",
"back_color",
"=",
"html_table_color",
"(",
"table",
"[",
"i",
"]",
",",
"item",
",",
"rgb_color",
")",
"if",
"min",
"(",
"back_color",
")",
"<",
"128",
":",
"color",
"=",
"\"white\"",
"part_2",
"+=",
"'<td style=\"background-color:\trgb({0},{1},{2});color:{3};padding:10px;height:7em;width:7em;\">'",
".",
"format",
"(",
"str",
"(",
"back_color",
"[",
"0",
"]",
")",
",",
"str",
"(",
"back_color",
"[",
"1",
"]",
")",
",",
"str",
"(",
"back_color",
"[",
"2",
"]",
")",
",",
"color",
")",
"+",
"str",
"(",
"item",
")",
"+",
"'</td>\\n'",
"part_2",
"+=",
"\"</tr>\\n\"",
"result",
"+=",
"'</tr>\\n'",
"part_2",
"+=",
"\"</table>\\n</td>\\n</tr>\\n</table>\\n\"",
"result",
"+=",
"part_2",
"return",
"result"
] |
Return HTML report file confusion matrix.
:param classes: matrix classes
:type classes: list
:param table: matrix
:type table : dict
:param rgb_color : input color
:type rgb_color : tuple
:param normalize : save normalize matrix flag
:type normalize : bool
:return: html_table as str
|
[
"Return",
"HTML",
"report",
"file",
"confusion",
"matrix",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_output.py#L96-L148
|
236,215
|
sepandhaghighi/pycm
|
pycm/pycm_output.py
|
html_overall_stat
|
def html_overall_stat(
overall_stat,
digit=5,
overall_param=None,
recommended_list=()):
"""
Return HTML report file overall stat.
:param overall_stat: overall stat
:type overall_stat : dict
:param digit: scale (the number of digits to the right of the decimal point in a number.)
:type digit : int
:param overall_param : Overall parameters list for print, Example : ["Kappa","Scott PI]
:type overall_param : list
:param recommended_list: recommended statistics list
:type recommended_list : list or tuple
:return: html_overall_stat as str
"""
result = ""
result += "<h2>Overall Statistics : </h2>\n"
result += '<table style="border:1px solid black;border-collapse: collapse;">\n'
overall_stat_keys = sorted(overall_stat.keys())
if isinstance(overall_param, list):
if set(overall_param) <= set(overall_stat_keys):
overall_stat_keys = sorted(overall_param)
if len(overall_stat_keys) < 1:
return ""
for i in overall_stat_keys:
background_color = DEFAULT_BACKGROUND_COLOR
if i in recommended_list:
background_color = RECOMMEND_BACKGROUND_COLOR
result += '<tr align="center">\n'
result += '<td style="border:1px solid black;padding:4px;text-align:left;background-color:{};"><a href="'.format(
background_color) + DOCUMENT_ADR + PARAMS_LINK[i] + '" style="text-decoration:None;">' + str(i) + '</a></td>\n'
if i in BENCHMARK_LIST:
background_color = BENCHMARK_COLOR[overall_stat[i]]
result += '<td style="border:1px solid black;padding:4px;background-color:{};">'.format(
background_color)
else:
result += '<td style="border:1px solid black;padding:4px;">'
result += rounder(overall_stat[i], digit) + '</td>\n'
result += "</tr>\n"
result += "</table>\n"
return result
|
python
|
def html_overall_stat(
overall_stat,
digit=5,
overall_param=None,
recommended_list=()):
"""
Return HTML report file overall stat.
:param overall_stat: overall stat
:type overall_stat : dict
:param digit: scale (the number of digits to the right of the decimal point in a number.)
:type digit : int
:param overall_param : Overall parameters list for print, Example : ["Kappa","Scott PI]
:type overall_param : list
:param recommended_list: recommended statistics list
:type recommended_list : list or tuple
:return: html_overall_stat as str
"""
result = ""
result += "<h2>Overall Statistics : </h2>\n"
result += '<table style="border:1px solid black;border-collapse: collapse;">\n'
overall_stat_keys = sorted(overall_stat.keys())
if isinstance(overall_param, list):
if set(overall_param) <= set(overall_stat_keys):
overall_stat_keys = sorted(overall_param)
if len(overall_stat_keys) < 1:
return ""
for i in overall_stat_keys:
background_color = DEFAULT_BACKGROUND_COLOR
if i in recommended_list:
background_color = RECOMMEND_BACKGROUND_COLOR
result += '<tr align="center">\n'
result += '<td style="border:1px solid black;padding:4px;text-align:left;background-color:{};"><a href="'.format(
background_color) + DOCUMENT_ADR + PARAMS_LINK[i] + '" style="text-decoration:None;">' + str(i) + '</a></td>\n'
if i in BENCHMARK_LIST:
background_color = BENCHMARK_COLOR[overall_stat[i]]
result += '<td style="border:1px solid black;padding:4px;background-color:{};">'.format(
background_color)
else:
result += '<td style="border:1px solid black;padding:4px;">'
result += rounder(overall_stat[i], digit) + '</td>\n'
result += "</tr>\n"
result += "</table>\n"
return result
|
[
"def",
"html_overall_stat",
"(",
"overall_stat",
",",
"digit",
"=",
"5",
",",
"overall_param",
"=",
"None",
",",
"recommended_list",
"=",
"(",
")",
")",
":",
"result",
"=",
"\"\"",
"result",
"+=",
"\"<h2>Overall Statistics : </h2>\\n\"",
"result",
"+=",
"'<table style=\"border:1px solid black;border-collapse: collapse;\">\\n'",
"overall_stat_keys",
"=",
"sorted",
"(",
"overall_stat",
".",
"keys",
"(",
")",
")",
"if",
"isinstance",
"(",
"overall_param",
",",
"list",
")",
":",
"if",
"set",
"(",
"overall_param",
")",
"<=",
"set",
"(",
"overall_stat_keys",
")",
":",
"overall_stat_keys",
"=",
"sorted",
"(",
"overall_param",
")",
"if",
"len",
"(",
"overall_stat_keys",
")",
"<",
"1",
":",
"return",
"\"\"",
"for",
"i",
"in",
"overall_stat_keys",
":",
"background_color",
"=",
"DEFAULT_BACKGROUND_COLOR",
"if",
"i",
"in",
"recommended_list",
":",
"background_color",
"=",
"RECOMMEND_BACKGROUND_COLOR",
"result",
"+=",
"'<tr align=\"center\">\\n'",
"result",
"+=",
"'<td style=\"border:1px solid black;padding:4px;text-align:left;background-color:{};\"><a href=\"'",
".",
"format",
"(",
"background_color",
")",
"+",
"DOCUMENT_ADR",
"+",
"PARAMS_LINK",
"[",
"i",
"]",
"+",
"'\" style=\"text-decoration:None;\">'",
"+",
"str",
"(",
"i",
")",
"+",
"'</a></td>\\n'",
"if",
"i",
"in",
"BENCHMARK_LIST",
":",
"background_color",
"=",
"BENCHMARK_COLOR",
"[",
"overall_stat",
"[",
"i",
"]",
"]",
"result",
"+=",
"'<td style=\"border:1px solid black;padding:4px;background-color:{};\">'",
".",
"format",
"(",
"background_color",
")",
"else",
":",
"result",
"+=",
"'<td style=\"border:1px solid black;padding:4px;\">'",
"result",
"+=",
"rounder",
"(",
"overall_stat",
"[",
"i",
"]",
",",
"digit",
")",
"+",
"'</td>\\n'",
"result",
"+=",
"\"</tr>\\n\"",
"result",
"+=",
"\"</table>\\n\"",
"return",
"result"
] |
Return HTML report file overall stat.
:param overall_stat: overall stat
:type overall_stat : dict
:param digit: scale (the number of digits to the right of the decimal point in a number.)
:type digit : int
:param overall_param : Overall parameters list for print, Example : ["Kappa","Scott PI]
:type overall_param : list
:param recommended_list: recommended statistics list
:type recommended_list : list or tuple
:return: html_overall_stat as str
|
[
"Return",
"HTML",
"report",
"file",
"overall",
"stat",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_output.py#L151-L194
|
236,216
|
sepandhaghighi/pycm
|
pycm/pycm_output.py
|
html_class_stat
|
def html_class_stat(
classes,
class_stat,
digit=5,
class_param=None,
recommended_list=()):
"""
Return HTML report file class_stat.
:param classes: matrix classes
:type classes: list
:param class_stat: class stat
:type class_stat:dict
:param digit: scale (the number of digits to the right of the decimal point in a number.)
:type digit : int
:param class_param : Class parameters list for print, Example : ["TPR","TNR","AUC"]
:type class_param : list
:param recommended_list: recommended statistics list
:type recommended_list : list or tuple
:return: html_class_stat as str
"""
result = ""
result += "<h2>Class Statistics : </h2>\n"
result += '<table style="border:1px solid black;border-collapse: collapse;">\n'
result += '<tr align="center">\n<td>Class</td>\n'
for i in classes:
result += '<td style="border:1px solid black;padding:4px;border-collapse: collapse;">' + \
str(i) + '</td>\n'
result += '<td>Description</td>\n'
result += '</tr>\n'
class_stat_keys = sorted(class_stat.keys())
if isinstance(class_param, list):
if set(class_param) <= set(class_stat_keys):
class_stat_keys = class_param
classes.sort()
if len(classes) < 1 or len(class_stat_keys) < 1:
return ""
for i in class_stat_keys:
background_color = DEFAULT_BACKGROUND_COLOR
if i in recommended_list:
background_color = RECOMMEND_BACKGROUND_COLOR
result += '<tr align="center" style="border:1px solid black;border-collapse: collapse;">\n'
result += '<td style="border:1px solid black;padding:4px;border-collapse: collapse;background-color:{};"><a href="'.format(
background_color) + DOCUMENT_ADR + PARAMS_LINK[i] + '" style="text-decoration:None;">' + str(i) + '</a></td>\n'
for j in classes:
if i in BENCHMARK_LIST:
background_color = BENCHMARK_COLOR[class_stat[i][j]]
result += '<td style="border:1px solid black;padding:4px;border-collapse: collapse;background-color:{};">'.format(
background_color)
else:
result += '<td style="border:1px solid black;padding:4px;border-collapse: collapse;">'
result += rounder(class_stat[i][j], digit) + '</td>\n'
params_text = PARAMS_DESCRIPTION[i]
if i not in CAPITALIZE_FILTER:
params_text = params_text.capitalize()
result += '<td style="border:1px solid black;padding:4px;border-collapse: collapse;text-align:left;">' + \
params_text + '</td>\n'
result += "</tr>\n"
result += "</table>\n"
return result
|
python
|
def html_class_stat(
classes,
class_stat,
digit=5,
class_param=None,
recommended_list=()):
"""
Return HTML report file class_stat.
:param classes: matrix classes
:type classes: list
:param class_stat: class stat
:type class_stat:dict
:param digit: scale (the number of digits to the right of the decimal point in a number.)
:type digit : int
:param class_param : Class parameters list for print, Example : ["TPR","TNR","AUC"]
:type class_param : list
:param recommended_list: recommended statistics list
:type recommended_list : list or tuple
:return: html_class_stat as str
"""
result = ""
result += "<h2>Class Statistics : </h2>\n"
result += '<table style="border:1px solid black;border-collapse: collapse;">\n'
result += '<tr align="center">\n<td>Class</td>\n'
for i in classes:
result += '<td style="border:1px solid black;padding:4px;border-collapse: collapse;">' + \
str(i) + '</td>\n'
result += '<td>Description</td>\n'
result += '</tr>\n'
class_stat_keys = sorted(class_stat.keys())
if isinstance(class_param, list):
if set(class_param) <= set(class_stat_keys):
class_stat_keys = class_param
classes.sort()
if len(classes) < 1 or len(class_stat_keys) < 1:
return ""
for i in class_stat_keys:
background_color = DEFAULT_BACKGROUND_COLOR
if i in recommended_list:
background_color = RECOMMEND_BACKGROUND_COLOR
result += '<tr align="center" style="border:1px solid black;border-collapse: collapse;">\n'
result += '<td style="border:1px solid black;padding:4px;border-collapse: collapse;background-color:{};"><a href="'.format(
background_color) + DOCUMENT_ADR + PARAMS_LINK[i] + '" style="text-decoration:None;">' + str(i) + '</a></td>\n'
for j in classes:
if i in BENCHMARK_LIST:
background_color = BENCHMARK_COLOR[class_stat[i][j]]
result += '<td style="border:1px solid black;padding:4px;border-collapse: collapse;background-color:{};">'.format(
background_color)
else:
result += '<td style="border:1px solid black;padding:4px;border-collapse: collapse;">'
result += rounder(class_stat[i][j], digit) + '</td>\n'
params_text = PARAMS_DESCRIPTION[i]
if i not in CAPITALIZE_FILTER:
params_text = params_text.capitalize()
result += '<td style="border:1px solid black;padding:4px;border-collapse: collapse;text-align:left;">' + \
params_text + '</td>\n'
result += "</tr>\n"
result += "</table>\n"
return result
|
[
"def",
"html_class_stat",
"(",
"classes",
",",
"class_stat",
",",
"digit",
"=",
"5",
",",
"class_param",
"=",
"None",
",",
"recommended_list",
"=",
"(",
")",
")",
":",
"result",
"=",
"\"\"",
"result",
"+=",
"\"<h2>Class Statistics : </h2>\\n\"",
"result",
"+=",
"'<table style=\"border:1px solid black;border-collapse: collapse;\">\\n'",
"result",
"+=",
"'<tr align=\"center\">\\n<td>Class</td>\\n'",
"for",
"i",
"in",
"classes",
":",
"result",
"+=",
"'<td style=\"border:1px solid black;padding:4px;border-collapse: collapse;\">'",
"+",
"str",
"(",
"i",
")",
"+",
"'</td>\\n'",
"result",
"+=",
"'<td>Description</td>\\n'",
"result",
"+=",
"'</tr>\\n'",
"class_stat_keys",
"=",
"sorted",
"(",
"class_stat",
".",
"keys",
"(",
")",
")",
"if",
"isinstance",
"(",
"class_param",
",",
"list",
")",
":",
"if",
"set",
"(",
"class_param",
")",
"<=",
"set",
"(",
"class_stat_keys",
")",
":",
"class_stat_keys",
"=",
"class_param",
"classes",
".",
"sort",
"(",
")",
"if",
"len",
"(",
"classes",
")",
"<",
"1",
"or",
"len",
"(",
"class_stat_keys",
")",
"<",
"1",
":",
"return",
"\"\"",
"for",
"i",
"in",
"class_stat_keys",
":",
"background_color",
"=",
"DEFAULT_BACKGROUND_COLOR",
"if",
"i",
"in",
"recommended_list",
":",
"background_color",
"=",
"RECOMMEND_BACKGROUND_COLOR",
"result",
"+=",
"'<tr align=\"center\" style=\"border:1px solid black;border-collapse: collapse;\">\\n'",
"result",
"+=",
"'<td style=\"border:1px solid black;padding:4px;border-collapse: collapse;background-color:{};\"><a href=\"'",
".",
"format",
"(",
"background_color",
")",
"+",
"DOCUMENT_ADR",
"+",
"PARAMS_LINK",
"[",
"i",
"]",
"+",
"'\" style=\"text-decoration:None;\">'",
"+",
"str",
"(",
"i",
")",
"+",
"'</a></td>\\n'",
"for",
"j",
"in",
"classes",
":",
"if",
"i",
"in",
"BENCHMARK_LIST",
":",
"background_color",
"=",
"BENCHMARK_COLOR",
"[",
"class_stat",
"[",
"i",
"]",
"[",
"j",
"]",
"]",
"result",
"+=",
"'<td style=\"border:1px solid black;padding:4px;border-collapse: collapse;background-color:{};\">'",
".",
"format",
"(",
"background_color",
")",
"else",
":",
"result",
"+=",
"'<td style=\"border:1px solid black;padding:4px;border-collapse: collapse;\">'",
"result",
"+=",
"rounder",
"(",
"class_stat",
"[",
"i",
"]",
"[",
"j",
"]",
",",
"digit",
")",
"+",
"'</td>\\n'",
"params_text",
"=",
"PARAMS_DESCRIPTION",
"[",
"i",
"]",
"if",
"i",
"not",
"in",
"CAPITALIZE_FILTER",
":",
"params_text",
"=",
"params_text",
".",
"capitalize",
"(",
")",
"result",
"+=",
"'<td style=\"border:1px solid black;padding:4px;border-collapse: collapse;text-align:left;\">'",
"+",
"params_text",
"+",
"'</td>\\n'",
"result",
"+=",
"\"</tr>\\n\"",
"result",
"+=",
"\"</table>\\n\"",
"return",
"result"
] |
Return HTML report file class_stat.
:param classes: matrix classes
:type classes: list
:param class_stat: class stat
:type class_stat:dict
:param digit: scale (the number of digits to the right of the decimal point in a number.)
:type digit : int
:param class_param : Class parameters list for print, Example : ["TPR","TNR","AUC"]
:type class_param : list
:param recommended_list: recommended statistics list
:type recommended_list : list or tuple
:return: html_class_stat as str
|
[
"Return",
"HTML",
"report",
"file",
"class_stat",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_output.py#L197-L256
|
236,217
|
sepandhaghighi/pycm
|
pycm/pycm_output.py
|
table_print
|
def table_print(classes, table):
"""
Return printable confusion matrix.
:param classes: classes list
:type classes:list
:param table: table
:type table:dict
:return: printable table as str
"""
classes_len = len(classes)
table_list = []
for key in classes:
table_list.extend(list(table[key].values()))
table_list.extend(classes)
table_max_length = max(map(len, map(str, table_list)))
shift = "%-" + str(7 + table_max_length) + "s"
result = shift % "Predict" + shift * \
classes_len % tuple(map(str, classes)) + "\n"
result = result + "Actual\n"
classes.sort()
for key in classes:
row = [table[key][i] for i in classes]
result += shift % str(key) + \
shift * classes_len % tuple(map(str, row)) + "\n\n"
if classes_len >= CLASS_NUMBER_THRESHOLD:
result += "\n" + "Warning : " + CLASS_NUMBER_WARNING + "\n"
return result
|
python
|
def table_print(classes, table):
"""
Return printable confusion matrix.
:param classes: classes list
:type classes:list
:param table: table
:type table:dict
:return: printable table as str
"""
classes_len = len(classes)
table_list = []
for key in classes:
table_list.extend(list(table[key].values()))
table_list.extend(classes)
table_max_length = max(map(len, map(str, table_list)))
shift = "%-" + str(7 + table_max_length) + "s"
result = shift % "Predict" + shift * \
classes_len % tuple(map(str, classes)) + "\n"
result = result + "Actual\n"
classes.sort()
for key in classes:
row = [table[key][i] for i in classes]
result += shift % str(key) + \
shift * classes_len % tuple(map(str, row)) + "\n\n"
if classes_len >= CLASS_NUMBER_THRESHOLD:
result += "\n" + "Warning : " + CLASS_NUMBER_WARNING + "\n"
return result
|
[
"def",
"table_print",
"(",
"classes",
",",
"table",
")",
":",
"classes_len",
"=",
"len",
"(",
"classes",
")",
"table_list",
"=",
"[",
"]",
"for",
"key",
"in",
"classes",
":",
"table_list",
".",
"extend",
"(",
"list",
"(",
"table",
"[",
"key",
"]",
".",
"values",
"(",
")",
")",
")",
"table_list",
".",
"extend",
"(",
"classes",
")",
"table_max_length",
"=",
"max",
"(",
"map",
"(",
"len",
",",
"map",
"(",
"str",
",",
"table_list",
")",
")",
")",
"shift",
"=",
"\"%-\"",
"+",
"str",
"(",
"7",
"+",
"table_max_length",
")",
"+",
"\"s\"",
"result",
"=",
"shift",
"%",
"\"Predict\"",
"+",
"shift",
"*",
"classes_len",
"%",
"tuple",
"(",
"map",
"(",
"str",
",",
"classes",
")",
")",
"+",
"\"\\n\"",
"result",
"=",
"result",
"+",
"\"Actual\\n\"",
"classes",
".",
"sort",
"(",
")",
"for",
"key",
"in",
"classes",
":",
"row",
"=",
"[",
"table",
"[",
"key",
"]",
"[",
"i",
"]",
"for",
"i",
"in",
"classes",
"]",
"result",
"+=",
"shift",
"%",
"str",
"(",
"key",
")",
"+",
"shift",
"*",
"classes_len",
"%",
"tuple",
"(",
"map",
"(",
"str",
",",
"row",
")",
")",
"+",
"\"\\n\\n\"",
"if",
"classes_len",
">=",
"CLASS_NUMBER_THRESHOLD",
":",
"result",
"+=",
"\"\\n\"",
"+",
"\"Warning : \"",
"+",
"CLASS_NUMBER_WARNING",
"+",
"\"\\n\"",
"return",
"result"
] |
Return printable confusion matrix.
:param classes: classes list
:type classes:list
:param table: table
:type table:dict
:return: printable table as str
|
[
"Return",
"printable",
"confusion",
"matrix",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_output.py#L286-L313
|
236,218
|
sepandhaghighi/pycm
|
pycm/pycm_output.py
|
csv_matrix_print
|
def csv_matrix_print(classes, table):
"""
Return matrix as csv data.
:param classes: classes list
:type classes:list
:param table: table
:type table:dict
:return:
"""
result = ""
classes.sort()
for i in classes:
for j in classes:
result += str(table[i][j]) + ","
result = result[:-1] + "\n"
return result[:-1]
|
python
|
def csv_matrix_print(classes, table):
"""
Return matrix as csv data.
:param classes: classes list
:type classes:list
:param table: table
:type table:dict
:return:
"""
result = ""
classes.sort()
for i in classes:
for j in classes:
result += str(table[i][j]) + ","
result = result[:-1] + "\n"
return result[:-1]
|
[
"def",
"csv_matrix_print",
"(",
"classes",
",",
"table",
")",
":",
"result",
"=",
"\"\"",
"classes",
".",
"sort",
"(",
")",
"for",
"i",
"in",
"classes",
":",
"for",
"j",
"in",
"classes",
":",
"result",
"+=",
"str",
"(",
"table",
"[",
"i",
"]",
"[",
"j",
"]",
")",
"+",
"\",\"",
"result",
"=",
"result",
"[",
":",
"-",
"1",
"]",
"+",
"\"\\n\"",
"return",
"result",
"[",
":",
"-",
"1",
"]"
] |
Return matrix as csv data.
:param classes: classes list
:type classes:list
:param table: table
:type table:dict
:return:
|
[
"Return",
"matrix",
"as",
"csv",
"data",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_output.py#L316-L332
|
236,219
|
sepandhaghighi/pycm
|
pycm/pycm_output.py
|
csv_print
|
def csv_print(classes, class_stat, digit=5, class_param=None):
"""
Return csv file data.
:param classes: classes list
:type classes:list
:param class_stat: statistic result for each class
:type class_stat:dict
:param digit: scale (the number of digits to the right of the decimal point in a number.)
:type digit : int
:param class_param : class parameters list for print, Example : ["TPR","TNR","AUC"]
:type class_param : list
:return: csv file data as str
"""
result = "Class"
classes.sort()
for item in classes:
result += ',"' + str(item) + '"'
result += "\n"
class_stat_keys = sorted(class_stat.keys())
if isinstance(class_param, list):
if set(class_param) <= set(class_stat_keys):
class_stat_keys = class_param
if len(class_stat_keys) < 1 or len(classes) < 1:
return ""
for key in class_stat_keys:
row = [rounder(class_stat[key][i], digit) for i in classes]
result += key + "," + ",".join(row)
result += "\n"
return result
|
python
|
def csv_print(classes, class_stat, digit=5, class_param=None):
"""
Return csv file data.
:param classes: classes list
:type classes:list
:param class_stat: statistic result for each class
:type class_stat:dict
:param digit: scale (the number of digits to the right of the decimal point in a number.)
:type digit : int
:param class_param : class parameters list for print, Example : ["TPR","TNR","AUC"]
:type class_param : list
:return: csv file data as str
"""
result = "Class"
classes.sort()
for item in classes:
result += ',"' + str(item) + '"'
result += "\n"
class_stat_keys = sorted(class_stat.keys())
if isinstance(class_param, list):
if set(class_param) <= set(class_stat_keys):
class_stat_keys = class_param
if len(class_stat_keys) < 1 or len(classes) < 1:
return ""
for key in class_stat_keys:
row = [rounder(class_stat[key][i], digit) for i in classes]
result += key + "," + ",".join(row)
result += "\n"
return result
|
[
"def",
"csv_print",
"(",
"classes",
",",
"class_stat",
",",
"digit",
"=",
"5",
",",
"class_param",
"=",
"None",
")",
":",
"result",
"=",
"\"Class\"",
"classes",
".",
"sort",
"(",
")",
"for",
"item",
"in",
"classes",
":",
"result",
"+=",
"',\"'",
"+",
"str",
"(",
"item",
")",
"+",
"'\"'",
"result",
"+=",
"\"\\n\"",
"class_stat_keys",
"=",
"sorted",
"(",
"class_stat",
".",
"keys",
"(",
")",
")",
"if",
"isinstance",
"(",
"class_param",
",",
"list",
")",
":",
"if",
"set",
"(",
"class_param",
")",
"<=",
"set",
"(",
"class_stat_keys",
")",
":",
"class_stat_keys",
"=",
"class_param",
"if",
"len",
"(",
"class_stat_keys",
")",
"<",
"1",
"or",
"len",
"(",
"classes",
")",
"<",
"1",
":",
"return",
"\"\"",
"for",
"key",
"in",
"class_stat_keys",
":",
"row",
"=",
"[",
"rounder",
"(",
"class_stat",
"[",
"key",
"]",
"[",
"i",
"]",
",",
"digit",
")",
"for",
"i",
"in",
"classes",
"]",
"result",
"+=",
"key",
"+",
"\",\"",
"+",
"\",\"",
".",
"join",
"(",
"row",
")",
"result",
"+=",
"\"\\n\"",
"return",
"result"
] |
Return csv file data.
:param classes: classes list
:type classes:list
:param class_stat: statistic result for each class
:type class_stat:dict
:param digit: scale (the number of digits to the right of the decimal point in a number.)
:type digit : int
:param class_param : class parameters list for print, Example : ["TPR","TNR","AUC"]
:type class_param : list
:return: csv file data as str
|
[
"Return",
"csv",
"file",
"data",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_output.py#L335-L364
|
236,220
|
sepandhaghighi/pycm
|
pycm/pycm_output.py
|
stat_print
|
def stat_print(
classes,
class_stat,
overall_stat,
digit=5,
overall_param=None,
class_param=None):
"""
Return printable statistics table.
:param classes: classes list
:type classes:list
:param class_stat: statistic result for each class
:type class_stat:dict
:param overall_stat : overall statistic result
:type overall_stat:dict
:param digit: scale (the number of digits to the right of the decimal point in a number.)
:type digit : int
:param overall_param : overall parameters list for print, Example : ["Kappa","Scott PI]
:type overall_param : list
:param class_param : class parameters list for print, Example : ["TPR","TNR","AUC"]
:type class_param : list
:return: printable result as str
"""
shift = max(map(len, PARAMS_DESCRIPTION.values())) + 5
classes_len = len(classes)
overall_stat_keys = sorted(overall_stat.keys())
result = ""
if isinstance(overall_param, list):
if set(overall_param) <= set(overall_stat_keys):
overall_stat_keys = sorted(overall_param)
if len(overall_stat_keys) > 0:
result = "Overall Statistics : " + "\n\n"
for key in overall_stat_keys:
result += key + " " * (shift - len(key) + 7) + \
rounder(overall_stat[key], digit) + "\n"
class_stat_keys = sorted(class_stat.keys())
if isinstance(class_param, list):
if set(class_param) <= set(class_stat_keys):
class_stat_keys = sorted(class_param)
classes.sort()
if len(class_stat_keys) > 0 and len(classes) > 0:
class_shift = max(
max(map(lambda x: len(str(x)), classes)) + 5, digit + 6, 14)
class_shift_format = "%-" + str(class_shift) + "s"
result += "\nClass Statistics :\n\n"
result += "Classes" + shift * " " + class_shift_format * \
classes_len % tuple(map(str, classes)) + "\n"
rounder_map = partial(rounder, digit=digit)
for key in class_stat_keys:
row = [class_stat[key][i] for i in classes]
params_text = PARAMS_DESCRIPTION[key]
if key not in CAPITALIZE_FILTER:
params_text = params_text.capitalize()
result += key + "(" + params_text + ")" + " " * (
shift - len(key) - len(PARAMS_DESCRIPTION[key]) + 5) + class_shift_format * classes_len % tuple(
map(rounder_map, row)) + "\n"
if classes_len >= CLASS_NUMBER_THRESHOLD:
result += "\n" + "Warning : " + CLASS_NUMBER_WARNING + "\n"
return result
|
python
|
def stat_print(
classes,
class_stat,
overall_stat,
digit=5,
overall_param=None,
class_param=None):
"""
Return printable statistics table.
:param classes: classes list
:type classes:list
:param class_stat: statistic result for each class
:type class_stat:dict
:param overall_stat : overall statistic result
:type overall_stat:dict
:param digit: scale (the number of digits to the right of the decimal point in a number.)
:type digit : int
:param overall_param : overall parameters list for print, Example : ["Kappa","Scott PI]
:type overall_param : list
:param class_param : class parameters list for print, Example : ["TPR","TNR","AUC"]
:type class_param : list
:return: printable result as str
"""
shift = max(map(len, PARAMS_DESCRIPTION.values())) + 5
classes_len = len(classes)
overall_stat_keys = sorted(overall_stat.keys())
result = ""
if isinstance(overall_param, list):
if set(overall_param) <= set(overall_stat_keys):
overall_stat_keys = sorted(overall_param)
if len(overall_stat_keys) > 0:
result = "Overall Statistics : " + "\n\n"
for key in overall_stat_keys:
result += key + " " * (shift - len(key) + 7) + \
rounder(overall_stat[key], digit) + "\n"
class_stat_keys = sorted(class_stat.keys())
if isinstance(class_param, list):
if set(class_param) <= set(class_stat_keys):
class_stat_keys = sorted(class_param)
classes.sort()
if len(class_stat_keys) > 0 and len(classes) > 0:
class_shift = max(
max(map(lambda x: len(str(x)), classes)) + 5, digit + 6, 14)
class_shift_format = "%-" + str(class_shift) + "s"
result += "\nClass Statistics :\n\n"
result += "Classes" + shift * " " + class_shift_format * \
classes_len % tuple(map(str, classes)) + "\n"
rounder_map = partial(rounder, digit=digit)
for key in class_stat_keys:
row = [class_stat[key][i] for i in classes]
params_text = PARAMS_DESCRIPTION[key]
if key not in CAPITALIZE_FILTER:
params_text = params_text.capitalize()
result += key + "(" + params_text + ")" + " " * (
shift - len(key) - len(PARAMS_DESCRIPTION[key]) + 5) + class_shift_format * classes_len % tuple(
map(rounder_map, row)) + "\n"
if classes_len >= CLASS_NUMBER_THRESHOLD:
result += "\n" + "Warning : " + CLASS_NUMBER_WARNING + "\n"
return result
|
[
"def",
"stat_print",
"(",
"classes",
",",
"class_stat",
",",
"overall_stat",
",",
"digit",
"=",
"5",
",",
"overall_param",
"=",
"None",
",",
"class_param",
"=",
"None",
")",
":",
"shift",
"=",
"max",
"(",
"map",
"(",
"len",
",",
"PARAMS_DESCRIPTION",
".",
"values",
"(",
")",
")",
")",
"+",
"5",
"classes_len",
"=",
"len",
"(",
"classes",
")",
"overall_stat_keys",
"=",
"sorted",
"(",
"overall_stat",
".",
"keys",
"(",
")",
")",
"result",
"=",
"\"\"",
"if",
"isinstance",
"(",
"overall_param",
",",
"list",
")",
":",
"if",
"set",
"(",
"overall_param",
")",
"<=",
"set",
"(",
"overall_stat_keys",
")",
":",
"overall_stat_keys",
"=",
"sorted",
"(",
"overall_param",
")",
"if",
"len",
"(",
"overall_stat_keys",
")",
">",
"0",
":",
"result",
"=",
"\"Overall Statistics : \"",
"+",
"\"\\n\\n\"",
"for",
"key",
"in",
"overall_stat_keys",
":",
"result",
"+=",
"key",
"+",
"\" \"",
"*",
"(",
"shift",
"-",
"len",
"(",
"key",
")",
"+",
"7",
")",
"+",
"rounder",
"(",
"overall_stat",
"[",
"key",
"]",
",",
"digit",
")",
"+",
"\"\\n\"",
"class_stat_keys",
"=",
"sorted",
"(",
"class_stat",
".",
"keys",
"(",
")",
")",
"if",
"isinstance",
"(",
"class_param",
",",
"list",
")",
":",
"if",
"set",
"(",
"class_param",
")",
"<=",
"set",
"(",
"class_stat_keys",
")",
":",
"class_stat_keys",
"=",
"sorted",
"(",
"class_param",
")",
"classes",
".",
"sort",
"(",
")",
"if",
"len",
"(",
"class_stat_keys",
")",
">",
"0",
"and",
"len",
"(",
"classes",
")",
">",
"0",
":",
"class_shift",
"=",
"max",
"(",
"max",
"(",
"map",
"(",
"lambda",
"x",
":",
"len",
"(",
"str",
"(",
"x",
")",
")",
",",
"classes",
")",
")",
"+",
"5",
",",
"digit",
"+",
"6",
",",
"14",
")",
"class_shift_format",
"=",
"\"%-\"",
"+",
"str",
"(",
"class_shift",
")",
"+",
"\"s\"",
"result",
"+=",
"\"\\nClass Statistics :\\n\\n\"",
"result",
"+=",
"\"Classes\"",
"+",
"shift",
"*",
"\" \"",
"+",
"class_shift_format",
"*",
"classes_len",
"%",
"tuple",
"(",
"map",
"(",
"str",
",",
"classes",
")",
")",
"+",
"\"\\n\"",
"rounder_map",
"=",
"partial",
"(",
"rounder",
",",
"digit",
"=",
"digit",
")",
"for",
"key",
"in",
"class_stat_keys",
":",
"row",
"=",
"[",
"class_stat",
"[",
"key",
"]",
"[",
"i",
"]",
"for",
"i",
"in",
"classes",
"]",
"params_text",
"=",
"PARAMS_DESCRIPTION",
"[",
"key",
"]",
"if",
"key",
"not",
"in",
"CAPITALIZE_FILTER",
":",
"params_text",
"=",
"params_text",
".",
"capitalize",
"(",
")",
"result",
"+=",
"key",
"+",
"\"(\"",
"+",
"params_text",
"+",
"\")\"",
"+",
"\" \"",
"*",
"(",
"shift",
"-",
"len",
"(",
"key",
")",
"-",
"len",
"(",
"PARAMS_DESCRIPTION",
"[",
"key",
"]",
")",
"+",
"5",
")",
"+",
"class_shift_format",
"*",
"classes_len",
"%",
"tuple",
"(",
"map",
"(",
"rounder_map",
",",
"row",
")",
")",
"+",
"\"\\n\"",
"if",
"classes_len",
">=",
"CLASS_NUMBER_THRESHOLD",
":",
"result",
"+=",
"\"\\n\"",
"+",
"\"Warning : \"",
"+",
"CLASS_NUMBER_WARNING",
"+",
"\"\\n\"",
"return",
"result"
] |
Return printable statistics table.
:param classes: classes list
:type classes:list
:param class_stat: statistic result for each class
:type class_stat:dict
:param overall_stat : overall statistic result
:type overall_stat:dict
:param digit: scale (the number of digits to the right of the decimal point in a number.)
:type digit : int
:param overall_param : overall parameters list for print, Example : ["Kappa","Scott PI]
:type overall_param : list
:param class_param : class parameters list for print, Example : ["TPR","TNR","AUC"]
:type class_param : list
:return: printable result as str
|
[
"Return",
"printable",
"statistics",
"table",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_output.py#L367-L426
|
236,221
|
sepandhaghighi/pycm
|
pycm/pycm_output.py
|
compare_report_print
|
def compare_report_print(sorted_list, scores, best_name):
"""
Return compare report.
:param sorted_list: sorted list of cm's
:type sorted_list: list
:param scores: scores of cm's
:type scores: dict
:param best_name: best cm name
:type best_name: str
:return: printable result as str
"""
title_items = ["Rank", "Name", "Class-Score", "Overall-Score"]
class_scores_len = map(lambda x: len(
str(x["class"])), list(scores.values()))
shifts = ["%-" +
str(len(sorted_list) +
4) +
"s", "%-" +
str(max(map(lambda x: len(str(x)), sorted_list)) +
4) +
"s", "%-" +
str(max(class_scores_len) + 11) + "s"]
result = ""
result += "Best : " + str(best_name) + "\n\n"
result += ("".join(shifts)
) % tuple(title_items[:-1]) + title_items[-1] + "\n"
prev_rank = 0
for index, cm in enumerate(sorted_list):
rank = index
if scores[sorted_list[rank]] == scores[sorted_list[prev_rank]]:
rank = prev_rank
result += ("".join(shifts)) % (str(rank + 1), str(cm),
str(scores[cm]["class"])) + str(scores[cm]["overall"]) + "\n"
prev_rank = rank
if best_name is None:
result += "\nWarning: " + COMPARE_RESULT_WARNING
return result
|
python
|
def compare_report_print(sorted_list, scores, best_name):
"""
Return compare report.
:param sorted_list: sorted list of cm's
:type sorted_list: list
:param scores: scores of cm's
:type scores: dict
:param best_name: best cm name
:type best_name: str
:return: printable result as str
"""
title_items = ["Rank", "Name", "Class-Score", "Overall-Score"]
class_scores_len = map(lambda x: len(
str(x["class"])), list(scores.values()))
shifts = ["%-" +
str(len(sorted_list) +
4) +
"s", "%-" +
str(max(map(lambda x: len(str(x)), sorted_list)) +
4) +
"s", "%-" +
str(max(class_scores_len) + 11) + "s"]
result = ""
result += "Best : " + str(best_name) + "\n\n"
result += ("".join(shifts)
) % tuple(title_items[:-1]) + title_items[-1] + "\n"
prev_rank = 0
for index, cm in enumerate(sorted_list):
rank = index
if scores[sorted_list[rank]] == scores[sorted_list[prev_rank]]:
rank = prev_rank
result += ("".join(shifts)) % (str(rank + 1), str(cm),
str(scores[cm]["class"])) + str(scores[cm]["overall"]) + "\n"
prev_rank = rank
if best_name is None:
result += "\nWarning: " + COMPARE_RESULT_WARNING
return result
|
[
"def",
"compare_report_print",
"(",
"sorted_list",
",",
"scores",
",",
"best_name",
")",
":",
"title_items",
"=",
"[",
"\"Rank\"",
",",
"\"Name\"",
",",
"\"Class-Score\"",
",",
"\"Overall-Score\"",
"]",
"class_scores_len",
"=",
"map",
"(",
"lambda",
"x",
":",
"len",
"(",
"str",
"(",
"x",
"[",
"\"class\"",
"]",
")",
")",
",",
"list",
"(",
"scores",
".",
"values",
"(",
")",
")",
")",
"shifts",
"=",
"[",
"\"%-\"",
"+",
"str",
"(",
"len",
"(",
"sorted_list",
")",
"+",
"4",
")",
"+",
"\"s\"",
",",
"\"%-\"",
"+",
"str",
"(",
"max",
"(",
"map",
"(",
"lambda",
"x",
":",
"len",
"(",
"str",
"(",
"x",
")",
")",
",",
"sorted_list",
")",
")",
"+",
"4",
")",
"+",
"\"s\"",
",",
"\"%-\"",
"+",
"str",
"(",
"max",
"(",
"class_scores_len",
")",
"+",
"11",
")",
"+",
"\"s\"",
"]",
"result",
"=",
"\"\"",
"result",
"+=",
"\"Best : \"",
"+",
"str",
"(",
"best_name",
")",
"+",
"\"\\n\\n\"",
"result",
"+=",
"(",
"\"\"",
".",
"join",
"(",
"shifts",
")",
")",
"%",
"tuple",
"(",
"title_items",
"[",
":",
"-",
"1",
"]",
")",
"+",
"title_items",
"[",
"-",
"1",
"]",
"+",
"\"\\n\"",
"prev_rank",
"=",
"0",
"for",
"index",
",",
"cm",
"in",
"enumerate",
"(",
"sorted_list",
")",
":",
"rank",
"=",
"index",
"if",
"scores",
"[",
"sorted_list",
"[",
"rank",
"]",
"]",
"==",
"scores",
"[",
"sorted_list",
"[",
"prev_rank",
"]",
"]",
":",
"rank",
"=",
"prev_rank",
"result",
"+=",
"(",
"\"\"",
".",
"join",
"(",
"shifts",
")",
")",
"%",
"(",
"str",
"(",
"rank",
"+",
"1",
")",
",",
"str",
"(",
"cm",
")",
",",
"str",
"(",
"scores",
"[",
"cm",
"]",
"[",
"\"class\"",
"]",
")",
")",
"+",
"str",
"(",
"scores",
"[",
"cm",
"]",
"[",
"\"overall\"",
"]",
")",
"+",
"\"\\n\"",
"prev_rank",
"=",
"rank",
"if",
"best_name",
"is",
"None",
":",
"result",
"+=",
"\"\\nWarning: \"",
"+",
"COMPARE_RESULT_WARNING",
"return",
"result"
] |
Return compare report.
:param sorted_list: sorted list of cm's
:type sorted_list: list
:param scores: scores of cm's
:type scores: dict
:param best_name: best cm name
:type best_name: str
:return: printable result as str
|
[
"Return",
"compare",
"report",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_output.py#L429-L466
|
236,222
|
sepandhaghighi/pycm
|
pycm/pycm_output.py
|
online_help
|
def online_help(param=None):
"""
Open online document in web browser.
:param param: input parameter
:type param : int or str
:return: None
"""
try:
PARAMS_LINK_KEYS = sorted(PARAMS_LINK.keys())
if param in PARAMS_LINK_KEYS:
webbrowser.open_new_tab(DOCUMENT_ADR + PARAMS_LINK[param])
elif param in range(1, len(PARAMS_LINK_KEYS) + 1):
webbrowser.open_new_tab(
DOCUMENT_ADR + PARAMS_LINK[PARAMS_LINK_KEYS[param - 1]])
else:
print("Please choose one parameter : \n")
print('Example : online_help("J") or online_help(2)\n')
for index, item in enumerate(PARAMS_LINK_KEYS):
print(str(index + 1) + "-" + item)
except Exception:
print("Error in online help")
|
python
|
def online_help(param=None):
"""
Open online document in web browser.
:param param: input parameter
:type param : int or str
:return: None
"""
try:
PARAMS_LINK_KEYS = sorted(PARAMS_LINK.keys())
if param in PARAMS_LINK_KEYS:
webbrowser.open_new_tab(DOCUMENT_ADR + PARAMS_LINK[param])
elif param in range(1, len(PARAMS_LINK_KEYS) + 1):
webbrowser.open_new_tab(
DOCUMENT_ADR + PARAMS_LINK[PARAMS_LINK_KEYS[param - 1]])
else:
print("Please choose one parameter : \n")
print('Example : online_help("J") or online_help(2)\n')
for index, item in enumerate(PARAMS_LINK_KEYS):
print(str(index + 1) + "-" + item)
except Exception:
print("Error in online help")
|
[
"def",
"online_help",
"(",
"param",
"=",
"None",
")",
":",
"try",
":",
"PARAMS_LINK_KEYS",
"=",
"sorted",
"(",
"PARAMS_LINK",
".",
"keys",
"(",
")",
")",
"if",
"param",
"in",
"PARAMS_LINK_KEYS",
":",
"webbrowser",
".",
"open_new_tab",
"(",
"DOCUMENT_ADR",
"+",
"PARAMS_LINK",
"[",
"param",
"]",
")",
"elif",
"param",
"in",
"range",
"(",
"1",
",",
"len",
"(",
"PARAMS_LINK_KEYS",
")",
"+",
"1",
")",
":",
"webbrowser",
".",
"open_new_tab",
"(",
"DOCUMENT_ADR",
"+",
"PARAMS_LINK",
"[",
"PARAMS_LINK_KEYS",
"[",
"param",
"-",
"1",
"]",
"]",
")",
"else",
":",
"print",
"(",
"\"Please choose one parameter : \\n\"",
")",
"print",
"(",
"'Example : online_help(\"J\") or online_help(2)\\n'",
")",
"for",
"index",
",",
"item",
"in",
"enumerate",
"(",
"PARAMS_LINK_KEYS",
")",
":",
"print",
"(",
"str",
"(",
"index",
"+",
"1",
")",
"+",
"\"-\"",
"+",
"item",
")",
"except",
"Exception",
":",
"print",
"(",
"\"Error in online help\"",
")"
] |
Open online document in web browser.
:param param: input parameter
:type param : int or str
:return: None
|
[
"Open",
"online",
"document",
"in",
"web",
"browser",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_output.py#L469-L490
|
236,223
|
sepandhaghighi/pycm
|
pycm/pycm_util.py
|
rounder
|
def rounder(input_number, digit=5):
"""
Round input number and convert to str.
:param input_number: input number
:type input_number : anything
:param digit: scale (the number of digits to the right of the decimal point in a number.)
:type digit : int
:return: round number as str
"""
if isinstance(input_number, tuple):
tuple_list = list(input_number)
tuple_str = []
for i in tuple_list:
if isfloat(i):
tuple_str.append(str(numpy.around(i, digit)))
else:
tuple_str.append(str(i))
return "(" + ",".join(tuple_str) + ")"
if isfloat(input_number):
return str(numpy.around(input_number, digit))
return str(input_number)
|
python
|
def rounder(input_number, digit=5):
"""
Round input number and convert to str.
:param input_number: input number
:type input_number : anything
:param digit: scale (the number of digits to the right of the decimal point in a number.)
:type digit : int
:return: round number as str
"""
if isinstance(input_number, tuple):
tuple_list = list(input_number)
tuple_str = []
for i in tuple_list:
if isfloat(i):
tuple_str.append(str(numpy.around(i, digit)))
else:
tuple_str.append(str(i))
return "(" + ",".join(tuple_str) + ")"
if isfloat(input_number):
return str(numpy.around(input_number, digit))
return str(input_number)
|
[
"def",
"rounder",
"(",
"input_number",
",",
"digit",
"=",
"5",
")",
":",
"if",
"isinstance",
"(",
"input_number",
",",
"tuple",
")",
":",
"tuple_list",
"=",
"list",
"(",
"input_number",
")",
"tuple_str",
"=",
"[",
"]",
"for",
"i",
"in",
"tuple_list",
":",
"if",
"isfloat",
"(",
"i",
")",
":",
"tuple_str",
".",
"append",
"(",
"str",
"(",
"numpy",
".",
"around",
"(",
"i",
",",
"digit",
")",
")",
")",
"else",
":",
"tuple_str",
".",
"append",
"(",
"str",
"(",
"i",
")",
")",
"return",
"\"(\"",
"+",
"\",\"",
".",
"join",
"(",
"tuple_str",
")",
"+",
"\")\"",
"if",
"isfloat",
"(",
"input_number",
")",
":",
"return",
"str",
"(",
"numpy",
".",
"around",
"(",
"input_number",
",",
"digit",
")",
")",
"return",
"str",
"(",
"input_number",
")"
] |
Round input number and convert to str.
:param input_number: input number
:type input_number : anything
:param digit: scale (the number of digits to the right of the decimal point in a number.)
:type digit : int
:return: round number as str
|
[
"Round",
"input",
"number",
"and",
"convert",
"to",
"str",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_util.py#L35-L56
|
236,224
|
sepandhaghighi/pycm
|
pycm/pycm_util.py
|
class_filter
|
def class_filter(classes, class_name):
"""
Filter classes by comparing two lists.
:param classes: matrix classes
:type classes: list
:param class_name: sub set of classes
:type class_name : list
:return: filtered classes as list
"""
result_classes = classes
if isinstance(class_name, list):
if set(class_name) <= set(classes):
result_classes = class_name
return result_classes
|
python
|
def class_filter(classes, class_name):
"""
Filter classes by comparing two lists.
:param classes: matrix classes
:type classes: list
:param class_name: sub set of classes
:type class_name : list
:return: filtered classes as list
"""
result_classes = classes
if isinstance(class_name, list):
if set(class_name) <= set(classes):
result_classes = class_name
return result_classes
|
[
"def",
"class_filter",
"(",
"classes",
",",
"class_name",
")",
":",
"result_classes",
"=",
"classes",
"if",
"isinstance",
"(",
"class_name",
",",
"list",
")",
":",
"if",
"set",
"(",
"class_name",
")",
"<=",
"set",
"(",
"classes",
")",
":",
"result_classes",
"=",
"class_name",
"return",
"result_classes"
] |
Filter classes by comparing two lists.
:param classes: matrix classes
:type classes: list
:param class_name: sub set of classes
:type class_name : list
:return: filtered classes as list
|
[
"Filter",
"classes",
"by",
"comparing",
"two",
"lists",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_util.py#L59-L73
|
236,225
|
sepandhaghighi/pycm
|
pycm/pycm_util.py
|
vector_check
|
def vector_check(vector):
"""
Check input vector items type.
:param vector: input vector
:type vector : list
:return: bool
"""
for i in vector:
if isinstance(i, int) is False:
return False
if i < 0:
return False
return True
|
python
|
def vector_check(vector):
"""
Check input vector items type.
:param vector: input vector
:type vector : list
:return: bool
"""
for i in vector:
if isinstance(i, int) is False:
return False
if i < 0:
return False
return True
|
[
"def",
"vector_check",
"(",
"vector",
")",
":",
"for",
"i",
"in",
"vector",
":",
"if",
"isinstance",
"(",
"i",
",",
"int",
")",
"is",
"False",
":",
"return",
"False",
"if",
"i",
"<",
"0",
":",
"return",
"False",
"return",
"True"
] |
Check input vector items type.
:param vector: input vector
:type vector : list
:return: bool
|
[
"Check",
"input",
"vector",
"items",
"type",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_util.py#L76-L89
|
236,226
|
sepandhaghighi/pycm
|
pycm/pycm_util.py
|
matrix_check
|
def matrix_check(table):
"""
Check input matrix format.
:param table: input matrix
:type table : dict
:return: bool
"""
try:
if len(table.keys()) == 0:
return False
for i in table.keys():
if table.keys() != table[i].keys() or vector_check(
list(table[i].values())) is False:
return False
return True
except Exception:
return False
|
python
|
def matrix_check(table):
"""
Check input matrix format.
:param table: input matrix
:type table : dict
:return: bool
"""
try:
if len(table.keys()) == 0:
return False
for i in table.keys():
if table.keys() != table[i].keys() or vector_check(
list(table[i].values())) is False:
return False
return True
except Exception:
return False
|
[
"def",
"matrix_check",
"(",
"table",
")",
":",
"try",
":",
"if",
"len",
"(",
"table",
".",
"keys",
"(",
")",
")",
"==",
"0",
":",
"return",
"False",
"for",
"i",
"in",
"table",
".",
"keys",
"(",
")",
":",
"if",
"table",
".",
"keys",
"(",
")",
"!=",
"table",
"[",
"i",
"]",
".",
"keys",
"(",
")",
"or",
"vector_check",
"(",
"list",
"(",
"table",
"[",
"i",
"]",
".",
"values",
"(",
")",
")",
")",
"is",
"False",
":",
"return",
"False",
"return",
"True",
"except",
"Exception",
":",
"return",
"False"
] |
Check input matrix format.
:param table: input matrix
:type table : dict
:return: bool
|
[
"Check",
"input",
"matrix",
"format",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_util.py#L92-L109
|
236,227
|
sepandhaghighi/pycm
|
pycm/pycm_util.py
|
vector_filter
|
def vector_filter(actual_vector, predict_vector):
"""
Convert different type of items in vectors to str.
:param actual_vector: actual values
:type actual_vector : list
:param predict_vector: predict value
:type predict_vector : list
:return: new actual and predict vector
"""
temp = []
temp.extend(actual_vector)
temp.extend(predict_vector)
types = set(map(type, temp))
if len(types) > 1:
return [list(map(str, actual_vector)), list(map(str, predict_vector))]
return [actual_vector, predict_vector]
|
python
|
def vector_filter(actual_vector, predict_vector):
"""
Convert different type of items in vectors to str.
:param actual_vector: actual values
:type actual_vector : list
:param predict_vector: predict value
:type predict_vector : list
:return: new actual and predict vector
"""
temp = []
temp.extend(actual_vector)
temp.extend(predict_vector)
types = set(map(type, temp))
if len(types) > 1:
return [list(map(str, actual_vector)), list(map(str, predict_vector))]
return [actual_vector, predict_vector]
|
[
"def",
"vector_filter",
"(",
"actual_vector",
",",
"predict_vector",
")",
":",
"temp",
"=",
"[",
"]",
"temp",
".",
"extend",
"(",
"actual_vector",
")",
"temp",
".",
"extend",
"(",
"predict_vector",
")",
"types",
"=",
"set",
"(",
"map",
"(",
"type",
",",
"temp",
")",
")",
"if",
"len",
"(",
"types",
")",
">",
"1",
":",
"return",
"[",
"list",
"(",
"map",
"(",
"str",
",",
"actual_vector",
")",
")",
",",
"list",
"(",
"map",
"(",
"str",
",",
"predict_vector",
")",
")",
"]",
"return",
"[",
"actual_vector",
",",
"predict_vector",
"]"
] |
Convert different type of items in vectors to str.
:param actual_vector: actual values
:type actual_vector : list
:param predict_vector: predict value
:type predict_vector : list
:return: new actual and predict vector
|
[
"Convert",
"different",
"type",
"of",
"items",
"in",
"vectors",
"to",
"str",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_util.py#L112-L128
|
236,228
|
sepandhaghighi/pycm
|
pycm/pycm_util.py
|
class_check
|
def class_check(vector):
"""
Check different items in matrix classes.
:param vector: input vector
:type vector : list
:return: bool
"""
for i in vector:
if not isinstance(i, type(vector[0])):
return False
return True
|
python
|
def class_check(vector):
"""
Check different items in matrix classes.
:param vector: input vector
:type vector : list
:return: bool
"""
for i in vector:
if not isinstance(i, type(vector[0])):
return False
return True
|
[
"def",
"class_check",
"(",
"vector",
")",
":",
"for",
"i",
"in",
"vector",
":",
"if",
"not",
"isinstance",
"(",
"i",
",",
"type",
"(",
"vector",
"[",
"0",
"]",
")",
")",
":",
"return",
"False",
"return",
"True"
] |
Check different items in matrix classes.
:param vector: input vector
:type vector : list
:return: bool
|
[
"Check",
"different",
"items",
"in",
"matrix",
"classes",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_util.py#L131-L142
|
236,229
|
sepandhaghighi/pycm
|
pycm/pycm_util.py
|
one_vs_all_func
|
def one_vs_all_func(classes, table, TP, TN, FP, FN, class_name):
"""
One-Vs-All mode handler.
:param classes: classes
:type classes : list
:param table: input matrix
:type table : dict
:param TP: true positive dict for all classes
:type TP : dict
:param TN: true negative dict for all classes
:type TN : dict
:param FP: false positive dict for all classes
:type FP : dict
:param FN: false negative dict for all classes
:type FN : dict
:param class_name : target class name for One-Vs-All mode
:type class_name : any valid type
:return: [classes , table ] as list
"""
try:
report_classes = [str(class_name), "~"]
report_table = {str(class_name): {str(class_name): TP[class_name],
"~": FN[class_name]},
"~": {str(class_name): FP[class_name],
"~": TN[class_name]}}
return [report_classes, report_table]
except Exception:
return [classes, table]
|
python
|
def one_vs_all_func(classes, table, TP, TN, FP, FN, class_name):
"""
One-Vs-All mode handler.
:param classes: classes
:type classes : list
:param table: input matrix
:type table : dict
:param TP: true positive dict for all classes
:type TP : dict
:param TN: true negative dict for all classes
:type TN : dict
:param FP: false positive dict for all classes
:type FP : dict
:param FN: false negative dict for all classes
:type FN : dict
:param class_name : target class name for One-Vs-All mode
:type class_name : any valid type
:return: [classes , table ] as list
"""
try:
report_classes = [str(class_name), "~"]
report_table = {str(class_name): {str(class_name): TP[class_name],
"~": FN[class_name]},
"~": {str(class_name): FP[class_name],
"~": TN[class_name]}}
return [report_classes, report_table]
except Exception:
return [classes, table]
|
[
"def",
"one_vs_all_func",
"(",
"classes",
",",
"table",
",",
"TP",
",",
"TN",
",",
"FP",
",",
"FN",
",",
"class_name",
")",
":",
"try",
":",
"report_classes",
"=",
"[",
"str",
"(",
"class_name",
")",
",",
"\"~\"",
"]",
"report_table",
"=",
"{",
"str",
"(",
"class_name",
")",
":",
"{",
"str",
"(",
"class_name",
")",
":",
"TP",
"[",
"class_name",
"]",
",",
"\"~\"",
":",
"FN",
"[",
"class_name",
"]",
"}",
",",
"\"~\"",
":",
"{",
"str",
"(",
"class_name",
")",
":",
"FP",
"[",
"class_name",
"]",
",",
"\"~\"",
":",
"TN",
"[",
"class_name",
"]",
"}",
"}",
"return",
"[",
"report_classes",
",",
"report_table",
"]",
"except",
"Exception",
":",
"return",
"[",
"classes",
",",
"table",
"]"
] |
One-Vs-All mode handler.
:param classes: classes
:type classes : list
:param table: input matrix
:type table : dict
:param TP: true positive dict for all classes
:type TP : dict
:param TN: true negative dict for all classes
:type TN : dict
:param FP: false positive dict for all classes
:type FP : dict
:param FN: false negative dict for all classes
:type FN : dict
:param class_name : target class name for One-Vs-All mode
:type class_name : any valid type
:return: [classes , table ] as list
|
[
"One",
"-",
"Vs",
"-",
"All",
"mode",
"handler",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_util.py#L158-L186
|
236,230
|
sepandhaghighi/pycm
|
pycm/pycm_util.py
|
normalized_table_calc
|
def normalized_table_calc(classes, table):
"""
Return normalized confusion matrix.
:param classes: classes list
:type classes:list
:param table: table
:type table:dict
:return: normalized table as dict
"""
map_dict = {k: 0 for k in classes}
new_table = {k: map_dict.copy() for k in classes}
for key in classes:
div = sum(table[key].values())
if div == 0:
div = 1
for item in classes:
new_table[key][item] = numpy.around(table[key][item] / div, 5)
return new_table
|
python
|
def normalized_table_calc(classes, table):
"""
Return normalized confusion matrix.
:param classes: classes list
:type classes:list
:param table: table
:type table:dict
:return: normalized table as dict
"""
map_dict = {k: 0 for k in classes}
new_table = {k: map_dict.copy() for k in classes}
for key in classes:
div = sum(table[key].values())
if div == 0:
div = 1
for item in classes:
new_table[key][item] = numpy.around(table[key][item] / div, 5)
return new_table
|
[
"def",
"normalized_table_calc",
"(",
"classes",
",",
"table",
")",
":",
"map_dict",
"=",
"{",
"k",
":",
"0",
"for",
"k",
"in",
"classes",
"}",
"new_table",
"=",
"{",
"k",
":",
"map_dict",
".",
"copy",
"(",
")",
"for",
"k",
"in",
"classes",
"}",
"for",
"key",
"in",
"classes",
":",
"div",
"=",
"sum",
"(",
"table",
"[",
"key",
"]",
".",
"values",
"(",
")",
")",
"if",
"div",
"==",
"0",
":",
"div",
"=",
"1",
"for",
"item",
"in",
"classes",
":",
"new_table",
"[",
"key",
"]",
"[",
"item",
"]",
"=",
"numpy",
".",
"around",
"(",
"table",
"[",
"key",
"]",
"[",
"item",
"]",
"/",
"div",
",",
"5",
")",
"return",
"new_table"
] |
Return normalized confusion matrix.
:param classes: classes list
:type classes:list
:param table: table
:type table:dict
:return: normalized table as dict
|
[
"Return",
"normalized",
"confusion",
"matrix",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_util.py#L189-L207
|
236,231
|
sepandhaghighi/pycm
|
pycm/pycm_util.py
|
transpose_func
|
def transpose_func(classes, table):
"""
Transpose table.
:param classes: classes
:type classes : list
:param table: input matrix
:type table : dict
:return: transposed table as dict
"""
transposed_table = table
for i, item1 in enumerate(classes):
for j, item2 in enumerate(classes):
if i > j:
temp = transposed_table[item1][item2]
transposed_table[item1][item2] = transposed_table[item2][item1]
transposed_table[item2][item1] = temp
return transposed_table
|
python
|
def transpose_func(classes, table):
"""
Transpose table.
:param classes: classes
:type classes : list
:param table: input matrix
:type table : dict
:return: transposed table as dict
"""
transposed_table = table
for i, item1 in enumerate(classes):
for j, item2 in enumerate(classes):
if i > j:
temp = transposed_table[item1][item2]
transposed_table[item1][item2] = transposed_table[item2][item1]
transposed_table[item2][item1] = temp
return transposed_table
|
[
"def",
"transpose_func",
"(",
"classes",
",",
"table",
")",
":",
"transposed_table",
"=",
"table",
"for",
"i",
",",
"item1",
"in",
"enumerate",
"(",
"classes",
")",
":",
"for",
"j",
",",
"item2",
"in",
"enumerate",
"(",
"classes",
")",
":",
"if",
"i",
">",
"j",
":",
"temp",
"=",
"transposed_table",
"[",
"item1",
"]",
"[",
"item2",
"]",
"transposed_table",
"[",
"item1",
"]",
"[",
"item2",
"]",
"=",
"transposed_table",
"[",
"item2",
"]",
"[",
"item1",
"]",
"transposed_table",
"[",
"item2",
"]",
"[",
"item1",
"]",
"=",
"temp",
"return",
"transposed_table"
] |
Transpose table.
:param classes: classes
:type classes : list
:param table: input matrix
:type table : dict
:return: transposed table as dict
|
[
"Transpose",
"table",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_util.py#L210-L227
|
236,232
|
sepandhaghighi/pycm
|
pycm/pycm_util.py
|
matrix_params_from_table
|
def matrix_params_from_table(table, transpose=False):
"""
Calculate TP,TN,FP,FN from confusion matrix.
:param table: input matrix
:type table : dict
:param transpose : transpose flag
:type transpose : bool
:return: [classes_list,table,TP,TN,FP,FN]
"""
classes = sorted(table.keys())
map_dict = {k: 0 for k in classes}
TP_dict = map_dict.copy()
TN_dict = map_dict.copy()
FP_dict = map_dict.copy()
FN_dict = map_dict.copy()
for i in classes:
TP_dict[i] = table[i][i]
sum_row = sum(list(table[i].values()))
for j in classes:
if j != i:
FN_dict[i] += table[i][j]
FP_dict[j] += table[i][j]
TN_dict[j] += sum_row - table[i][j]
if transpose:
temp = FN_dict
FN_dict = FP_dict
FP_dict = temp
table = transpose_func(classes, table)
return [classes, table, TP_dict, TN_dict, FP_dict, FN_dict]
|
python
|
def matrix_params_from_table(table, transpose=False):
"""
Calculate TP,TN,FP,FN from confusion matrix.
:param table: input matrix
:type table : dict
:param transpose : transpose flag
:type transpose : bool
:return: [classes_list,table,TP,TN,FP,FN]
"""
classes = sorted(table.keys())
map_dict = {k: 0 for k in classes}
TP_dict = map_dict.copy()
TN_dict = map_dict.copy()
FP_dict = map_dict.copy()
FN_dict = map_dict.copy()
for i in classes:
TP_dict[i] = table[i][i]
sum_row = sum(list(table[i].values()))
for j in classes:
if j != i:
FN_dict[i] += table[i][j]
FP_dict[j] += table[i][j]
TN_dict[j] += sum_row - table[i][j]
if transpose:
temp = FN_dict
FN_dict = FP_dict
FP_dict = temp
table = transpose_func(classes, table)
return [classes, table, TP_dict, TN_dict, FP_dict, FN_dict]
|
[
"def",
"matrix_params_from_table",
"(",
"table",
",",
"transpose",
"=",
"False",
")",
":",
"classes",
"=",
"sorted",
"(",
"table",
".",
"keys",
"(",
")",
")",
"map_dict",
"=",
"{",
"k",
":",
"0",
"for",
"k",
"in",
"classes",
"}",
"TP_dict",
"=",
"map_dict",
".",
"copy",
"(",
")",
"TN_dict",
"=",
"map_dict",
".",
"copy",
"(",
")",
"FP_dict",
"=",
"map_dict",
".",
"copy",
"(",
")",
"FN_dict",
"=",
"map_dict",
".",
"copy",
"(",
")",
"for",
"i",
"in",
"classes",
":",
"TP_dict",
"[",
"i",
"]",
"=",
"table",
"[",
"i",
"]",
"[",
"i",
"]",
"sum_row",
"=",
"sum",
"(",
"list",
"(",
"table",
"[",
"i",
"]",
".",
"values",
"(",
")",
")",
")",
"for",
"j",
"in",
"classes",
":",
"if",
"j",
"!=",
"i",
":",
"FN_dict",
"[",
"i",
"]",
"+=",
"table",
"[",
"i",
"]",
"[",
"j",
"]",
"FP_dict",
"[",
"j",
"]",
"+=",
"table",
"[",
"i",
"]",
"[",
"j",
"]",
"TN_dict",
"[",
"j",
"]",
"+=",
"sum_row",
"-",
"table",
"[",
"i",
"]",
"[",
"j",
"]",
"if",
"transpose",
":",
"temp",
"=",
"FN_dict",
"FN_dict",
"=",
"FP_dict",
"FP_dict",
"=",
"temp",
"table",
"=",
"transpose_func",
"(",
"classes",
",",
"table",
")",
"return",
"[",
"classes",
",",
"table",
",",
"TP_dict",
",",
"TN_dict",
",",
"FP_dict",
",",
"FN_dict",
"]"
] |
Calculate TP,TN,FP,FN from confusion matrix.
:param table: input matrix
:type table : dict
:param transpose : transpose flag
:type transpose : bool
:return: [classes_list,table,TP,TN,FP,FN]
|
[
"Calculate",
"TP",
"TN",
"FP",
"FN",
"from",
"confusion",
"matrix",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_util.py#L230-L259
|
236,233
|
sepandhaghighi/pycm
|
pycm/pycm_util.py
|
matrix_params_calc
|
def matrix_params_calc(actual_vector, predict_vector, sample_weight):
"""
Calculate TP,TN,FP,FN for each class.
:param actual_vector: actual values
:type actual_vector : list
:param predict_vector: predict value
:type predict_vector : list
:param sample_weight : sample weights list
:type sample_weight : list
:return: [classes_list,table,TP,TN,FP,FN]
"""
if isinstance(actual_vector, numpy.ndarray):
actual_vector = actual_vector.tolist()
if isinstance(predict_vector, numpy.ndarray):
predict_vector = predict_vector.tolist()
classes = set(actual_vector).union(set(predict_vector))
classes = sorted(classes)
map_dict = {k: 0 for k in classes}
table = {k: map_dict.copy() for k in classes}
weight_vector = [1] * len(actual_vector)
if isinstance(sample_weight, (list, numpy.ndarray)):
if len(sample_weight) == len(actual_vector):
weight_vector = sample_weight
for index, item in enumerate(actual_vector):
table[item][predict_vector[index]] += 1 * weight_vector[index]
[classes, table, TP_dict, TN_dict, FP_dict,
FN_dict] = matrix_params_from_table(table)
return [classes, table, TP_dict, TN_dict, FP_dict, FN_dict]
|
python
|
def matrix_params_calc(actual_vector, predict_vector, sample_weight):
"""
Calculate TP,TN,FP,FN for each class.
:param actual_vector: actual values
:type actual_vector : list
:param predict_vector: predict value
:type predict_vector : list
:param sample_weight : sample weights list
:type sample_weight : list
:return: [classes_list,table,TP,TN,FP,FN]
"""
if isinstance(actual_vector, numpy.ndarray):
actual_vector = actual_vector.tolist()
if isinstance(predict_vector, numpy.ndarray):
predict_vector = predict_vector.tolist()
classes = set(actual_vector).union(set(predict_vector))
classes = sorted(classes)
map_dict = {k: 0 for k in classes}
table = {k: map_dict.copy() for k in classes}
weight_vector = [1] * len(actual_vector)
if isinstance(sample_weight, (list, numpy.ndarray)):
if len(sample_weight) == len(actual_vector):
weight_vector = sample_weight
for index, item in enumerate(actual_vector):
table[item][predict_vector[index]] += 1 * weight_vector[index]
[classes, table, TP_dict, TN_dict, FP_dict,
FN_dict] = matrix_params_from_table(table)
return [classes, table, TP_dict, TN_dict, FP_dict, FN_dict]
|
[
"def",
"matrix_params_calc",
"(",
"actual_vector",
",",
"predict_vector",
",",
"sample_weight",
")",
":",
"if",
"isinstance",
"(",
"actual_vector",
",",
"numpy",
".",
"ndarray",
")",
":",
"actual_vector",
"=",
"actual_vector",
".",
"tolist",
"(",
")",
"if",
"isinstance",
"(",
"predict_vector",
",",
"numpy",
".",
"ndarray",
")",
":",
"predict_vector",
"=",
"predict_vector",
".",
"tolist",
"(",
")",
"classes",
"=",
"set",
"(",
"actual_vector",
")",
".",
"union",
"(",
"set",
"(",
"predict_vector",
")",
")",
"classes",
"=",
"sorted",
"(",
"classes",
")",
"map_dict",
"=",
"{",
"k",
":",
"0",
"for",
"k",
"in",
"classes",
"}",
"table",
"=",
"{",
"k",
":",
"map_dict",
".",
"copy",
"(",
")",
"for",
"k",
"in",
"classes",
"}",
"weight_vector",
"=",
"[",
"1",
"]",
"*",
"len",
"(",
"actual_vector",
")",
"if",
"isinstance",
"(",
"sample_weight",
",",
"(",
"list",
",",
"numpy",
".",
"ndarray",
")",
")",
":",
"if",
"len",
"(",
"sample_weight",
")",
"==",
"len",
"(",
"actual_vector",
")",
":",
"weight_vector",
"=",
"sample_weight",
"for",
"index",
",",
"item",
"in",
"enumerate",
"(",
"actual_vector",
")",
":",
"table",
"[",
"item",
"]",
"[",
"predict_vector",
"[",
"index",
"]",
"]",
"+=",
"1",
"*",
"weight_vector",
"[",
"index",
"]",
"[",
"classes",
",",
"table",
",",
"TP_dict",
",",
"TN_dict",
",",
"FP_dict",
",",
"FN_dict",
"]",
"=",
"matrix_params_from_table",
"(",
"table",
")",
"return",
"[",
"classes",
",",
"table",
",",
"TP_dict",
",",
"TN_dict",
",",
"FP_dict",
",",
"FN_dict",
"]"
] |
Calculate TP,TN,FP,FN for each class.
:param actual_vector: actual values
:type actual_vector : list
:param predict_vector: predict value
:type predict_vector : list
:param sample_weight : sample weights list
:type sample_weight : list
:return: [classes_list,table,TP,TN,FP,FN]
|
[
"Calculate",
"TP",
"TN",
"FP",
"FN",
"for",
"each",
"class",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_util.py#L262-L290
|
236,234
|
sepandhaghighi/pycm
|
pycm/pycm_util.py
|
imbalance_check
|
def imbalance_check(P):
"""
Check if the dataset is imbalanced.
:param P: condition positive
:type P : dict
:return: is_imbalanced as bool
"""
p_list = list(P.values())
max_value = max(p_list)
min_value = min(p_list)
if min_value > 0:
balance_ratio = max_value / min_value
else:
balance_ratio = max_value
is_imbalanced = False
if balance_ratio > BALANCE_RATIO_THRESHOLD:
is_imbalanced = True
return is_imbalanced
|
python
|
def imbalance_check(P):
"""
Check if the dataset is imbalanced.
:param P: condition positive
:type P : dict
:return: is_imbalanced as bool
"""
p_list = list(P.values())
max_value = max(p_list)
min_value = min(p_list)
if min_value > 0:
balance_ratio = max_value / min_value
else:
balance_ratio = max_value
is_imbalanced = False
if balance_ratio > BALANCE_RATIO_THRESHOLD:
is_imbalanced = True
return is_imbalanced
|
[
"def",
"imbalance_check",
"(",
"P",
")",
":",
"p_list",
"=",
"list",
"(",
"P",
".",
"values",
"(",
")",
")",
"max_value",
"=",
"max",
"(",
"p_list",
")",
"min_value",
"=",
"min",
"(",
"p_list",
")",
"if",
"min_value",
">",
"0",
":",
"balance_ratio",
"=",
"max_value",
"/",
"min_value",
"else",
":",
"balance_ratio",
"=",
"max_value",
"is_imbalanced",
"=",
"False",
"if",
"balance_ratio",
">",
"BALANCE_RATIO_THRESHOLD",
":",
"is_imbalanced",
"=",
"True",
"return",
"is_imbalanced"
] |
Check if the dataset is imbalanced.
:param P: condition positive
:type P : dict
:return: is_imbalanced as bool
|
[
"Check",
"if",
"the",
"dataset",
"is",
"imbalanced",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_util.py#L293-L311
|
236,235
|
sepandhaghighi/pycm
|
pycm/pycm_util.py
|
binary_check
|
def binary_check(classes):
"""
Check if the problem is a binary classification.
:param classes: all classes name
:type classes : list
:return: is_binary as bool
"""
num_classes = len(classes)
is_binary = False
if num_classes == 2:
is_binary = True
return is_binary
|
python
|
def binary_check(classes):
"""
Check if the problem is a binary classification.
:param classes: all classes name
:type classes : list
:return: is_binary as bool
"""
num_classes = len(classes)
is_binary = False
if num_classes == 2:
is_binary = True
return is_binary
|
[
"def",
"binary_check",
"(",
"classes",
")",
":",
"num_classes",
"=",
"len",
"(",
"classes",
")",
"is_binary",
"=",
"False",
"if",
"num_classes",
"==",
"2",
":",
"is_binary",
"=",
"True",
"return",
"is_binary"
] |
Check if the problem is a binary classification.
:param classes: all classes name
:type classes : list
:return: is_binary as bool
|
[
"Check",
"if",
"the",
"problem",
"is",
"a",
"binary",
"classification",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_util.py#L314-L326
|
236,236
|
sepandhaghighi/pycm
|
pycm/pycm_util.py
|
statistic_recommend
|
def statistic_recommend(classes, P):
"""
Return recommend parameters which are more suitable due to the input dataset characteristics.
:param classes: all classes name
:type classes : list
:param P: condition positive
:type P : dict
:return: recommendation_list as list
"""
if imbalance_check(P):
return IMBALANCED_RECOMMEND
if binary_check(classes):
return BINARY_RECOMMEND
return MULTICLASS_RECOMMEND
|
python
|
def statistic_recommend(classes, P):
"""
Return recommend parameters which are more suitable due to the input dataset characteristics.
:param classes: all classes name
:type classes : list
:param P: condition positive
:type P : dict
:return: recommendation_list as list
"""
if imbalance_check(P):
return IMBALANCED_RECOMMEND
if binary_check(classes):
return BINARY_RECOMMEND
return MULTICLASS_RECOMMEND
|
[
"def",
"statistic_recommend",
"(",
"classes",
",",
"P",
")",
":",
"if",
"imbalance_check",
"(",
"P",
")",
":",
"return",
"IMBALANCED_RECOMMEND",
"if",
"binary_check",
"(",
"classes",
")",
":",
"return",
"BINARY_RECOMMEND",
"return",
"MULTICLASS_RECOMMEND"
] |
Return recommend parameters which are more suitable due to the input dataset characteristics.
:param classes: all classes name
:type classes : list
:param P: condition positive
:type P : dict
:return: recommendation_list as list
|
[
"Return",
"recommend",
"parameters",
"which",
"are",
"more",
"suitable",
"due",
"to",
"the",
"input",
"dataset",
"characteristics",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_util.py#L329-L343
|
236,237
|
sepandhaghighi/pycm
|
Otherfiles/version_check.py
|
print_result
|
def print_result(failed=False):
"""
Print final result.
:param failed: failed flag
:type failed: bool
:return: None
"""
message = "Version tag tests "
if not failed:
print("\n" + message + "passed!")
else:
print("\n" + message + "failed!")
print("Passed : " + str(TEST_NUMBER - Failed) + "/" + str(TEST_NUMBER))
|
python
|
def print_result(failed=False):
"""
Print final result.
:param failed: failed flag
:type failed: bool
:return: None
"""
message = "Version tag tests "
if not failed:
print("\n" + message + "passed!")
else:
print("\n" + message + "failed!")
print("Passed : " + str(TEST_NUMBER - Failed) + "/" + str(TEST_NUMBER))
|
[
"def",
"print_result",
"(",
"failed",
"=",
"False",
")",
":",
"message",
"=",
"\"Version tag tests \"",
"if",
"not",
"failed",
":",
"print",
"(",
"\"\\n\"",
"+",
"message",
"+",
"\"passed!\"",
")",
"else",
":",
"print",
"(",
"\"\\n\"",
"+",
"message",
"+",
"\"failed!\"",
")",
"print",
"(",
"\"Passed : \"",
"+",
"str",
"(",
"TEST_NUMBER",
"-",
"Failed",
")",
"+",
"\"/\"",
"+",
"str",
"(",
"TEST_NUMBER",
")",
")"
] |
Print final result.
:param failed: failed flag
:type failed: bool
:return: None
|
[
"Print",
"final",
"result",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/Otherfiles/version_check.py#L40-L53
|
236,238
|
sepandhaghighi/pycm
|
pycm/pycm_overall_func.py
|
AUNP_calc
|
def AUNP_calc(classes, P, POP, AUC_dict):
"""
Calculate AUNP.
:param classes: classes
:type classes : list
:param P: condition positive
:type P : dict
:param POP: population
:type POP : dict
:param AUC_dict: AUC (Area under the ROC curve) for each class
:type AUC_dict : dict
:return: AUNP as float
"""
try:
result = 0
for i in classes:
result += (P[i] / POP[i]) * AUC_dict[i]
return result
except Exception:
return "None"
|
python
|
def AUNP_calc(classes, P, POP, AUC_dict):
"""
Calculate AUNP.
:param classes: classes
:type classes : list
:param P: condition positive
:type P : dict
:param POP: population
:type POP : dict
:param AUC_dict: AUC (Area under the ROC curve) for each class
:type AUC_dict : dict
:return: AUNP as float
"""
try:
result = 0
for i in classes:
result += (P[i] / POP[i]) * AUC_dict[i]
return result
except Exception:
return "None"
|
[
"def",
"AUNP_calc",
"(",
"classes",
",",
"P",
",",
"POP",
",",
"AUC_dict",
")",
":",
"try",
":",
"result",
"=",
"0",
"for",
"i",
"in",
"classes",
":",
"result",
"+=",
"(",
"P",
"[",
"i",
"]",
"/",
"POP",
"[",
"i",
"]",
")",
"*",
"AUC_dict",
"[",
"i",
"]",
"return",
"result",
"except",
"Exception",
":",
"return",
"\"None\""
] |
Calculate AUNP.
:param classes: classes
:type classes : list
:param P: condition positive
:type P : dict
:param POP: population
:type POP : dict
:param AUC_dict: AUC (Area under the ROC curve) for each class
:type AUC_dict : dict
:return: AUNP as float
|
[
"Calculate",
"AUNP",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_overall_func.py#L43-L63
|
236,239
|
sepandhaghighi/pycm
|
pycm/pycm_overall_func.py
|
overall_MCC_calc
|
def overall_MCC_calc(classes, table, TOP, P):
"""
Calculate Overall_MCC.
:param classes: classes
:type classes : list
:param table: input matrix
:type table : dict
:param TOP: test outcome positive
:type TOP : dict
:param P: condition positive
:type P : dict
:return: Overall_MCC as float
"""
try:
cov_x_y = 0
cov_x_x = 0
cov_y_y = 0
matrix_sum = sum(list(TOP.values()))
for i in classes:
cov_x_x += TOP[i] * (matrix_sum - TOP[i])
cov_y_y += P[i] * (matrix_sum - P[i])
cov_x_y += (table[i][i] * matrix_sum - P[i] * TOP[i])
return cov_x_y / (math.sqrt(cov_y_y * cov_x_x))
except Exception:
return "None"
|
python
|
def overall_MCC_calc(classes, table, TOP, P):
"""
Calculate Overall_MCC.
:param classes: classes
:type classes : list
:param table: input matrix
:type table : dict
:param TOP: test outcome positive
:type TOP : dict
:param P: condition positive
:type P : dict
:return: Overall_MCC as float
"""
try:
cov_x_y = 0
cov_x_x = 0
cov_y_y = 0
matrix_sum = sum(list(TOP.values()))
for i in classes:
cov_x_x += TOP[i] * (matrix_sum - TOP[i])
cov_y_y += P[i] * (matrix_sum - P[i])
cov_x_y += (table[i][i] * matrix_sum - P[i] * TOP[i])
return cov_x_y / (math.sqrt(cov_y_y * cov_x_x))
except Exception:
return "None"
|
[
"def",
"overall_MCC_calc",
"(",
"classes",
",",
"table",
",",
"TOP",
",",
"P",
")",
":",
"try",
":",
"cov_x_y",
"=",
"0",
"cov_x_x",
"=",
"0",
"cov_y_y",
"=",
"0",
"matrix_sum",
"=",
"sum",
"(",
"list",
"(",
"TOP",
".",
"values",
"(",
")",
")",
")",
"for",
"i",
"in",
"classes",
":",
"cov_x_x",
"+=",
"TOP",
"[",
"i",
"]",
"*",
"(",
"matrix_sum",
"-",
"TOP",
"[",
"i",
"]",
")",
"cov_y_y",
"+=",
"P",
"[",
"i",
"]",
"*",
"(",
"matrix_sum",
"-",
"P",
"[",
"i",
"]",
")",
"cov_x_y",
"+=",
"(",
"table",
"[",
"i",
"]",
"[",
"i",
"]",
"*",
"matrix_sum",
"-",
"P",
"[",
"i",
"]",
"*",
"TOP",
"[",
"i",
"]",
")",
"return",
"cov_x_y",
"/",
"(",
"math",
".",
"sqrt",
"(",
"cov_y_y",
"*",
"cov_x_x",
")",
")",
"except",
"Exception",
":",
"return",
"\"None\""
] |
Calculate Overall_MCC.
:param classes: classes
:type classes : list
:param table: input matrix
:type table : dict
:param TOP: test outcome positive
:type TOP : dict
:param P: condition positive
:type P : dict
:return: Overall_MCC as float
|
[
"Calculate",
"Overall_MCC",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_overall_func.py#L108-L133
|
236,240
|
sepandhaghighi/pycm
|
pycm/pycm_overall_func.py
|
convex_combination
|
def convex_combination(classes, TP, TOP, P, class_name, modified=False):
"""
Calculate Overall_CEN coefficient.
:param classes: classes
:type classes : list
:param TP: true Positive Dict For All Classes
:type TP : dict
:param TOP: test outcome positive
:type TOP : dict
:param P: condition positive
:type P : dict
:param class_name: reviewed class name
:type class_name : any valid type
:param modified : modified mode flag
:type modified : bool
:return: coefficient as float
"""
try:
class_number = len(classes)
alpha = 1
if class_number == 2:
alpha = 0
matrix_sum = sum(list(TOP.values()))
TP_sum = sum(list(TP.values()))
up = TOP[class_name] + P[class_name]
down = 2 * matrix_sum
if modified:
down -= (alpha * TP_sum)
up -= TP[class_name]
return up / down
except Exception:
return "None"
|
python
|
def convex_combination(classes, TP, TOP, P, class_name, modified=False):
"""
Calculate Overall_CEN coefficient.
:param classes: classes
:type classes : list
:param TP: true Positive Dict For All Classes
:type TP : dict
:param TOP: test outcome positive
:type TOP : dict
:param P: condition positive
:type P : dict
:param class_name: reviewed class name
:type class_name : any valid type
:param modified : modified mode flag
:type modified : bool
:return: coefficient as float
"""
try:
class_number = len(classes)
alpha = 1
if class_number == 2:
alpha = 0
matrix_sum = sum(list(TOP.values()))
TP_sum = sum(list(TP.values()))
up = TOP[class_name] + P[class_name]
down = 2 * matrix_sum
if modified:
down -= (alpha * TP_sum)
up -= TP[class_name]
return up / down
except Exception:
return "None"
|
[
"def",
"convex_combination",
"(",
"classes",
",",
"TP",
",",
"TOP",
",",
"P",
",",
"class_name",
",",
"modified",
"=",
"False",
")",
":",
"try",
":",
"class_number",
"=",
"len",
"(",
"classes",
")",
"alpha",
"=",
"1",
"if",
"class_number",
"==",
"2",
":",
"alpha",
"=",
"0",
"matrix_sum",
"=",
"sum",
"(",
"list",
"(",
"TOP",
".",
"values",
"(",
")",
")",
")",
"TP_sum",
"=",
"sum",
"(",
"list",
"(",
"TP",
".",
"values",
"(",
")",
")",
")",
"up",
"=",
"TOP",
"[",
"class_name",
"]",
"+",
"P",
"[",
"class_name",
"]",
"down",
"=",
"2",
"*",
"matrix_sum",
"if",
"modified",
":",
"down",
"-=",
"(",
"alpha",
"*",
"TP_sum",
")",
"up",
"-=",
"TP",
"[",
"class_name",
"]",
"return",
"up",
"/",
"down",
"except",
"Exception",
":",
"return",
"\"None\""
] |
Calculate Overall_CEN coefficient.
:param classes: classes
:type classes : list
:param TP: true Positive Dict For All Classes
:type TP : dict
:param TOP: test outcome positive
:type TOP : dict
:param P: condition positive
:type P : dict
:param class_name: reviewed class name
:type class_name : any valid type
:param modified : modified mode flag
:type modified : bool
:return: coefficient as float
|
[
"Calculate",
"Overall_CEN",
"coefficient",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_overall_func.py#L136-L168
|
236,241
|
sepandhaghighi/pycm
|
pycm/pycm_overall_func.py
|
ncr
|
def ncr(n, r):
"""
Calculate n choose r.
:param n: n
:type n : int
:param r: r
:type r :int
:return: n choose r as int
"""
r = min(r, n - r)
numer = reduce(op.mul, range(n, n - r, -1), 1)
denom = reduce(op.mul, range(1, r + 1), 1)
return numer // denom
|
python
|
def ncr(n, r):
"""
Calculate n choose r.
:param n: n
:type n : int
:param r: r
:type r :int
:return: n choose r as int
"""
r = min(r, n - r)
numer = reduce(op.mul, range(n, n - r, -1), 1)
denom = reduce(op.mul, range(1, r + 1), 1)
return numer // denom
|
[
"def",
"ncr",
"(",
"n",
",",
"r",
")",
":",
"r",
"=",
"min",
"(",
"r",
",",
"n",
"-",
"r",
")",
"numer",
"=",
"reduce",
"(",
"op",
".",
"mul",
",",
"range",
"(",
"n",
",",
"n",
"-",
"r",
",",
"-",
"1",
")",
",",
"1",
")",
"denom",
"=",
"reduce",
"(",
"op",
".",
"mul",
",",
"range",
"(",
"1",
",",
"r",
"+",
"1",
")",
",",
"1",
")",
"return",
"numer",
"//",
"denom"
] |
Calculate n choose r.
:param n: n
:type n : int
:param r: r
:type r :int
:return: n choose r as int
|
[
"Calculate",
"n",
"choose",
"r",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_overall_func.py#L199-L212
|
236,242
|
sepandhaghighi/pycm
|
pycm/pycm_overall_func.py
|
p_value_calc
|
def p_value_calc(TP, POP, NIR):
"""
Calculate p_value.
:param TP: true positive
:type TP : dict
:param POP: population
:type POP : int
:param NIR: no information rate
:type NIR : float
:return: p_value as float
"""
try:
n = POP
x = sum(list(TP.values()))
p = NIR
result = 0
for j in range(x):
result += ncr(n, j) * (p ** j) * ((1 - p) ** (n - j))
return 1 - result
except Exception:
return "None"
|
python
|
def p_value_calc(TP, POP, NIR):
"""
Calculate p_value.
:param TP: true positive
:type TP : dict
:param POP: population
:type POP : int
:param NIR: no information rate
:type NIR : float
:return: p_value as float
"""
try:
n = POP
x = sum(list(TP.values()))
p = NIR
result = 0
for j in range(x):
result += ncr(n, j) * (p ** j) * ((1 - p) ** (n - j))
return 1 - result
except Exception:
return "None"
|
[
"def",
"p_value_calc",
"(",
"TP",
",",
"POP",
",",
"NIR",
")",
":",
"try",
":",
"n",
"=",
"POP",
"x",
"=",
"sum",
"(",
"list",
"(",
"TP",
".",
"values",
"(",
")",
")",
")",
"p",
"=",
"NIR",
"result",
"=",
"0",
"for",
"j",
"in",
"range",
"(",
"x",
")",
":",
"result",
"+=",
"ncr",
"(",
"n",
",",
"j",
")",
"*",
"(",
"p",
"**",
"j",
")",
"*",
"(",
"(",
"1",
"-",
"p",
")",
"**",
"(",
"n",
"-",
"j",
")",
")",
"return",
"1",
"-",
"result",
"except",
"Exception",
":",
"return",
"\"None\""
] |
Calculate p_value.
:param TP: true positive
:type TP : dict
:param POP: population
:type POP : int
:param NIR: no information rate
:type NIR : float
:return: p_value as float
|
[
"Calculate",
"p_value",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_overall_func.py#L215-L236
|
236,243
|
sepandhaghighi/pycm
|
pycm/pycm_overall_func.py
|
hamming_calc
|
def hamming_calc(TP, POP):
"""
Calculate hamming loss.
:param TP: true positive
:type TP : dict
:param POP: population
:type POP : int
:return: hamming loss as float
"""
try:
length = POP
return (1 / length) * (length - sum(TP.values()))
except Exception:
return "None"
|
python
|
def hamming_calc(TP, POP):
"""
Calculate hamming loss.
:param TP: true positive
:type TP : dict
:param POP: population
:type POP : int
:return: hamming loss as float
"""
try:
length = POP
return (1 / length) * (length - sum(TP.values()))
except Exception:
return "None"
|
[
"def",
"hamming_calc",
"(",
"TP",
",",
"POP",
")",
":",
"try",
":",
"length",
"=",
"POP",
"return",
"(",
"1",
"/",
"length",
")",
"*",
"(",
"length",
"-",
"sum",
"(",
"TP",
".",
"values",
"(",
")",
")",
")",
"except",
"Exception",
":",
"return",
"\"None\""
] |
Calculate hamming loss.
:param TP: true positive
:type TP : dict
:param POP: population
:type POP : int
:return: hamming loss as float
|
[
"Calculate",
"hamming",
"loss",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_overall_func.py#L257-L271
|
236,244
|
sepandhaghighi/pycm
|
pycm/pycm_overall_func.py
|
zero_one_loss_calc
|
def zero_one_loss_calc(TP, POP):
"""
Calculate zero-one loss.
:param TP: true Positive
:type TP : dict
:param POP: population
:type POP : int
:return: zero_one loss as integer
"""
try:
length = POP
return (length - sum(TP.values()))
except Exception:
return "None"
|
python
|
def zero_one_loss_calc(TP, POP):
"""
Calculate zero-one loss.
:param TP: true Positive
:type TP : dict
:param POP: population
:type POP : int
:return: zero_one loss as integer
"""
try:
length = POP
return (length - sum(TP.values()))
except Exception:
return "None"
|
[
"def",
"zero_one_loss_calc",
"(",
"TP",
",",
"POP",
")",
":",
"try",
":",
"length",
"=",
"POP",
"return",
"(",
"length",
"-",
"sum",
"(",
"TP",
".",
"values",
"(",
")",
")",
")",
"except",
"Exception",
":",
"return",
"\"None\""
] |
Calculate zero-one loss.
:param TP: true Positive
:type TP : dict
:param POP: population
:type POP : int
:return: zero_one loss as integer
|
[
"Calculate",
"zero",
"-",
"one",
"loss",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_overall_func.py#L274-L288
|
236,245
|
sepandhaghighi/pycm
|
pycm/pycm_overall_func.py
|
entropy_calc
|
def entropy_calc(item, POP):
"""
Calculate reference and response likelihood.
:param item : TOP or P
:type item : dict
:param POP: population
:type POP : dict
:return: reference or response likelihood as float
"""
try:
result = 0
for i in item.keys():
likelihood = item[i] / POP[i]
if likelihood != 0:
result += likelihood * math.log(likelihood, 2)
return -result
except Exception:
return "None"
|
python
|
def entropy_calc(item, POP):
"""
Calculate reference and response likelihood.
:param item : TOP or P
:type item : dict
:param POP: population
:type POP : dict
:return: reference or response likelihood as float
"""
try:
result = 0
for i in item.keys():
likelihood = item[i] / POP[i]
if likelihood != 0:
result += likelihood * math.log(likelihood, 2)
return -result
except Exception:
return "None"
|
[
"def",
"entropy_calc",
"(",
"item",
",",
"POP",
")",
":",
"try",
":",
"result",
"=",
"0",
"for",
"i",
"in",
"item",
".",
"keys",
"(",
")",
":",
"likelihood",
"=",
"item",
"[",
"i",
"]",
"/",
"POP",
"[",
"i",
"]",
"if",
"likelihood",
"!=",
"0",
":",
"result",
"+=",
"likelihood",
"*",
"math",
".",
"log",
"(",
"likelihood",
",",
"2",
")",
"return",
"-",
"result",
"except",
"Exception",
":",
"return",
"\"None\""
] |
Calculate reference and response likelihood.
:param item : TOP or P
:type item : dict
:param POP: population
:type POP : dict
:return: reference or response likelihood as float
|
[
"Calculate",
"reference",
"and",
"response",
"likelihood",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_overall_func.py#L291-L309
|
236,246
|
sepandhaghighi/pycm
|
pycm/pycm_overall_func.py
|
cross_entropy_calc
|
def cross_entropy_calc(TOP, P, POP):
"""
Calculate cross entropy.
:param TOP: test outcome positive
:type TOP : dict
:param P: condition positive
:type P : dict
:param POP: population
:type POP : dict
:return: cross entropy as float
"""
try:
result = 0
for i in TOP.keys():
reference_likelihood = P[i] / POP[i]
response_likelihood = TOP[i] / POP[i]
if response_likelihood != 0 and reference_likelihood != 0:
result += reference_likelihood * \
math.log(response_likelihood, 2)
return -result
except Exception:
return "None"
|
python
|
def cross_entropy_calc(TOP, P, POP):
"""
Calculate cross entropy.
:param TOP: test outcome positive
:type TOP : dict
:param P: condition positive
:type P : dict
:param POP: population
:type POP : dict
:return: cross entropy as float
"""
try:
result = 0
for i in TOP.keys():
reference_likelihood = P[i] / POP[i]
response_likelihood = TOP[i] / POP[i]
if response_likelihood != 0 and reference_likelihood != 0:
result += reference_likelihood * \
math.log(response_likelihood, 2)
return -result
except Exception:
return "None"
|
[
"def",
"cross_entropy_calc",
"(",
"TOP",
",",
"P",
",",
"POP",
")",
":",
"try",
":",
"result",
"=",
"0",
"for",
"i",
"in",
"TOP",
".",
"keys",
"(",
")",
":",
"reference_likelihood",
"=",
"P",
"[",
"i",
"]",
"/",
"POP",
"[",
"i",
"]",
"response_likelihood",
"=",
"TOP",
"[",
"i",
"]",
"/",
"POP",
"[",
"i",
"]",
"if",
"response_likelihood",
"!=",
"0",
"and",
"reference_likelihood",
"!=",
"0",
":",
"result",
"+=",
"reference_likelihood",
"*",
"math",
".",
"log",
"(",
"response_likelihood",
",",
"2",
")",
"return",
"-",
"result",
"except",
"Exception",
":",
"return",
"\"None\""
] |
Calculate cross entropy.
:param TOP: test outcome positive
:type TOP : dict
:param P: condition positive
:type P : dict
:param POP: population
:type POP : dict
:return: cross entropy as float
|
[
"Calculate",
"cross",
"entropy",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_overall_func.py#L327-L349
|
236,247
|
sepandhaghighi/pycm
|
pycm/pycm_overall_func.py
|
joint_entropy_calc
|
def joint_entropy_calc(classes, table, POP):
"""
Calculate joint entropy.
:param classes: confusion matrix classes
:type classes : list
:param table: confusion matrix table
:type table : dict
:param POP: population
:type POP : dict
:return: joint entropy as float
"""
try:
result = 0
for i in classes:
for index, j in enumerate(classes):
p_prime = table[i][j] / POP[i]
if p_prime != 0:
result += p_prime * math.log(p_prime, 2)
return -result
except Exception:
return "None"
|
python
|
def joint_entropy_calc(classes, table, POP):
"""
Calculate joint entropy.
:param classes: confusion matrix classes
:type classes : list
:param table: confusion matrix table
:type table : dict
:param POP: population
:type POP : dict
:return: joint entropy as float
"""
try:
result = 0
for i in classes:
for index, j in enumerate(classes):
p_prime = table[i][j] / POP[i]
if p_prime != 0:
result += p_prime * math.log(p_prime, 2)
return -result
except Exception:
return "None"
|
[
"def",
"joint_entropy_calc",
"(",
"classes",
",",
"table",
",",
"POP",
")",
":",
"try",
":",
"result",
"=",
"0",
"for",
"i",
"in",
"classes",
":",
"for",
"index",
",",
"j",
"in",
"enumerate",
"(",
"classes",
")",
":",
"p_prime",
"=",
"table",
"[",
"i",
"]",
"[",
"j",
"]",
"/",
"POP",
"[",
"i",
"]",
"if",
"p_prime",
"!=",
"0",
":",
"result",
"+=",
"p_prime",
"*",
"math",
".",
"log",
"(",
"p_prime",
",",
"2",
")",
"return",
"-",
"result",
"except",
"Exception",
":",
"return",
"\"None\""
] |
Calculate joint entropy.
:param classes: confusion matrix classes
:type classes : list
:param table: confusion matrix table
:type table : dict
:param POP: population
:type POP : dict
:return: joint entropy as float
|
[
"Calculate",
"joint",
"entropy",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_overall_func.py#L352-L373
|
236,248
|
sepandhaghighi/pycm
|
pycm/pycm_overall_func.py
|
conditional_entropy_calc
|
def conditional_entropy_calc(classes, table, P, POP):
"""
Calculate conditional entropy.
:param classes: confusion matrix classes
:type classes : list
:param table: confusion matrix table
:type table : dict
:param P: condition positive
:type P : dict
:param POP: population
:type POP : dict
:return: conditional entropy as float
"""
try:
result = 0
for i in classes:
temp = 0
for index, j in enumerate(classes):
p_prime = 0
if P[i] != 0:
p_prime = table[i][j] / P[i]
if p_prime != 0:
temp += p_prime * math.log(p_prime, 2)
result += temp * (P[i] / POP[i])
return -result
except Exception:
return "None"
|
python
|
def conditional_entropy_calc(classes, table, P, POP):
"""
Calculate conditional entropy.
:param classes: confusion matrix classes
:type classes : list
:param table: confusion matrix table
:type table : dict
:param P: condition positive
:type P : dict
:param POP: population
:type POP : dict
:return: conditional entropy as float
"""
try:
result = 0
for i in classes:
temp = 0
for index, j in enumerate(classes):
p_prime = 0
if P[i] != 0:
p_prime = table[i][j] / P[i]
if p_prime != 0:
temp += p_prime * math.log(p_prime, 2)
result += temp * (P[i] / POP[i])
return -result
except Exception:
return "None"
|
[
"def",
"conditional_entropy_calc",
"(",
"classes",
",",
"table",
",",
"P",
",",
"POP",
")",
":",
"try",
":",
"result",
"=",
"0",
"for",
"i",
"in",
"classes",
":",
"temp",
"=",
"0",
"for",
"index",
",",
"j",
"in",
"enumerate",
"(",
"classes",
")",
":",
"p_prime",
"=",
"0",
"if",
"P",
"[",
"i",
"]",
"!=",
"0",
":",
"p_prime",
"=",
"table",
"[",
"i",
"]",
"[",
"j",
"]",
"/",
"P",
"[",
"i",
"]",
"if",
"p_prime",
"!=",
"0",
":",
"temp",
"+=",
"p_prime",
"*",
"math",
".",
"log",
"(",
"p_prime",
",",
"2",
")",
"result",
"+=",
"temp",
"*",
"(",
"P",
"[",
"i",
"]",
"/",
"POP",
"[",
"i",
"]",
")",
"return",
"-",
"result",
"except",
"Exception",
":",
"return",
"\"None\""
] |
Calculate conditional entropy.
:param classes: confusion matrix classes
:type classes : list
:param table: confusion matrix table
:type table : dict
:param P: condition positive
:type P : dict
:param POP: population
:type POP : dict
:return: conditional entropy as float
|
[
"Calculate",
"conditional",
"entropy",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_overall_func.py#L376-L403
|
236,249
|
sepandhaghighi/pycm
|
pycm/pycm_overall_func.py
|
lambda_B_calc
|
def lambda_B_calc(classes, table, TOP, POP):
"""
Calculate Goodman and Kruskal's lambda B.
:param classes: confusion matrix classes
:type classes : list
:param table: confusion matrix table
:type table : dict
:param TOP: test outcome positive
:type TOP : dict
:param POP: population
:type POP : int
:return: Goodman and Kruskal's lambda B as float
"""
try:
result = 0
length = POP
maxresponse = max(list(TOP.values()))
for i in classes:
result += max(list(table[i].values()))
result = (result - maxresponse) / (length - maxresponse)
return result
except Exception:
return "None"
|
python
|
def lambda_B_calc(classes, table, TOP, POP):
"""
Calculate Goodman and Kruskal's lambda B.
:param classes: confusion matrix classes
:type classes : list
:param table: confusion matrix table
:type table : dict
:param TOP: test outcome positive
:type TOP : dict
:param POP: population
:type POP : int
:return: Goodman and Kruskal's lambda B as float
"""
try:
result = 0
length = POP
maxresponse = max(list(TOP.values()))
for i in classes:
result += max(list(table[i].values()))
result = (result - maxresponse) / (length - maxresponse)
return result
except Exception:
return "None"
|
[
"def",
"lambda_B_calc",
"(",
"classes",
",",
"table",
",",
"TOP",
",",
"POP",
")",
":",
"try",
":",
"result",
"=",
"0",
"length",
"=",
"POP",
"maxresponse",
"=",
"max",
"(",
"list",
"(",
"TOP",
".",
"values",
"(",
")",
")",
")",
"for",
"i",
"in",
"classes",
":",
"result",
"+=",
"max",
"(",
"list",
"(",
"table",
"[",
"i",
"]",
".",
"values",
"(",
")",
")",
")",
"result",
"=",
"(",
"result",
"-",
"maxresponse",
")",
"/",
"(",
"length",
"-",
"maxresponse",
")",
"return",
"result",
"except",
"Exception",
":",
"return",
"\"None\""
] |
Calculate Goodman and Kruskal's lambda B.
:param classes: confusion matrix classes
:type classes : list
:param table: confusion matrix table
:type table : dict
:param TOP: test outcome positive
:type TOP : dict
:param POP: population
:type POP : int
:return: Goodman and Kruskal's lambda B as float
|
[
"Calculate",
"Goodman",
"and",
"Kruskal",
"s",
"lambda",
"B",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_overall_func.py#L446-L469
|
236,250
|
sepandhaghighi/pycm
|
pycm/pycm_overall_func.py
|
lambda_A_calc
|
def lambda_A_calc(classes, table, P, POP):
"""
Calculate Goodman and Kruskal's lambda A.
:param classes: confusion matrix classes
:type classes : list
:param table: confusion matrix table
:type table : dict
:param P: condition positive
:type P : dict
:param POP: population
:type POP : int
:return: Goodman and Kruskal's lambda A as float
"""
try:
result = 0
maxreference = max(list(P.values()))
length = POP
for i in classes:
col = []
for col_item in table.values():
col.append(col_item[i])
result += max(col)
result = (result - maxreference) / (length - maxreference)
return result
except Exception:
return "None"
|
python
|
def lambda_A_calc(classes, table, P, POP):
"""
Calculate Goodman and Kruskal's lambda A.
:param classes: confusion matrix classes
:type classes : list
:param table: confusion matrix table
:type table : dict
:param P: condition positive
:type P : dict
:param POP: population
:type POP : int
:return: Goodman and Kruskal's lambda A as float
"""
try:
result = 0
maxreference = max(list(P.values()))
length = POP
for i in classes:
col = []
for col_item in table.values():
col.append(col_item[i])
result += max(col)
result = (result - maxreference) / (length - maxreference)
return result
except Exception:
return "None"
|
[
"def",
"lambda_A_calc",
"(",
"classes",
",",
"table",
",",
"P",
",",
"POP",
")",
":",
"try",
":",
"result",
"=",
"0",
"maxreference",
"=",
"max",
"(",
"list",
"(",
"P",
".",
"values",
"(",
")",
")",
")",
"length",
"=",
"POP",
"for",
"i",
"in",
"classes",
":",
"col",
"=",
"[",
"]",
"for",
"col_item",
"in",
"table",
".",
"values",
"(",
")",
":",
"col",
".",
"append",
"(",
"col_item",
"[",
"i",
"]",
")",
"result",
"+=",
"max",
"(",
"col",
")",
"result",
"=",
"(",
"result",
"-",
"maxreference",
")",
"/",
"(",
"length",
"-",
"maxreference",
")",
"return",
"result",
"except",
"Exception",
":",
"return",
"\"None\""
] |
Calculate Goodman and Kruskal's lambda A.
:param classes: confusion matrix classes
:type classes : list
:param table: confusion matrix table
:type table : dict
:param P: condition positive
:type P : dict
:param POP: population
:type POP : int
:return: Goodman and Kruskal's lambda A as float
|
[
"Calculate",
"Goodman",
"and",
"Kruskal",
"s",
"lambda",
"A",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_overall_func.py#L472-L498
|
236,251
|
sepandhaghighi/pycm
|
pycm/pycm_overall_func.py
|
chi_square_calc
|
def chi_square_calc(classes, table, TOP, P, POP):
"""
Calculate chi-squared.
:param classes: confusion matrix classes
:type classes : list
:param table: confusion matrix table
:type table : dict
:param TOP: test outcome positive
:type TOP : dict
:param P: condition positive
:type P : dict
:param POP: population
:type POP : dict
:return: chi-squared as float
"""
try:
result = 0
for i in classes:
for index, j in enumerate(classes):
expected = (TOP[j] * P[i]) / (POP[i])
result += ((table[i][j] - expected)**2) / expected
return result
except Exception:
return "None"
|
python
|
def chi_square_calc(classes, table, TOP, P, POP):
"""
Calculate chi-squared.
:param classes: confusion matrix classes
:type classes : list
:param table: confusion matrix table
:type table : dict
:param TOP: test outcome positive
:type TOP : dict
:param P: condition positive
:type P : dict
:param POP: population
:type POP : dict
:return: chi-squared as float
"""
try:
result = 0
for i in classes:
for index, j in enumerate(classes):
expected = (TOP[j] * P[i]) / (POP[i])
result += ((table[i][j] - expected)**2) / expected
return result
except Exception:
return "None"
|
[
"def",
"chi_square_calc",
"(",
"classes",
",",
"table",
",",
"TOP",
",",
"P",
",",
"POP",
")",
":",
"try",
":",
"result",
"=",
"0",
"for",
"i",
"in",
"classes",
":",
"for",
"index",
",",
"j",
"in",
"enumerate",
"(",
"classes",
")",
":",
"expected",
"=",
"(",
"TOP",
"[",
"j",
"]",
"*",
"P",
"[",
"i",
"]",
")",
"/",
"(",
"POP",
"[",
"i",
"]",
")",
"result",
"+=",
"(",
"(",
"table",
"[",
"i",
"]",
"[",
"j",
"]",
"-",
"expected",
")",
"**",
"2",
")",
"/",
"expected",
"return",
"result",
"except",
"Exception",
":",
"return",
"\"None\""
] |
Calculate chi-squared.
:param classes: confusion matrix classes
:type classes : list
:param table: confusion matrix table
:type table : dict
:param TOP: test outcome positive
:type TOP : dict
:param P: condition positive
:type P : dict
:param POP: population
:type POP : dict
:return: chi-squared as float
|
[
"Calculate",
"chi",
"-",
"squared",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_overall_func.py#L501-L525
|
236,252
|
sepandhaghighi/pycm
|
pycm/pycm_overall_func.py
|
kappa_se_calc
|
def kappa_se_calc(PA, PE, POP):
"""
Calculate kappa standard error.
:param PA: observed agreement among raters (overall accuracy)
:type PA : float
:param PE: hypothetical probability of chance agreement (random accuracy)
:type PE : float
:param POP: population
:type POP:int
:return: kappa standard error as float
"""
try:
result = math.sqrt((PA * (1 - PA)) / (POP * ((1 - PE)**2)))
return result
except Exception:
return "None"
|
python
|
def kappa_se_calc(PA, PE, POP):
"""
Calculate kappa standard error.
:param PA: observed agreement among raters (overall accuracy)
:type PA : float
:param PE: hypothetical probability of chance agreement (random accuracy)
:type PE : float
:param POP: population
:type POP:int
:return: kappa standard error as float
"""
try:
result = math.sqrt((PA * (1 - PA)) / (POP * ((1 - PE)**2)))
return result
except Exception:
return "None"
|
[
"def",
"kappa_se_calc",
"(",
"PA",
",",
"PE",
",",
"POP",
")",
":",
"try",
":",
"result",
"=",
"math",
".",
"sqrt",
"(",
"(",
"PA",
"*",
"(",
"1",
"-",
"PA",
")",
")",
"/",
"(",
"POP",
"*",
"(",
"(",
"1",
"-",
"PE",
")",
"**",
"2",
")",
")",
")",
"return",
"result",
"except",
"Exception",
":",
"return",
"\"None\""
] |
Calculate kappa standard error.
:param PA: observed agreement among raters (overall accuracy)
:type PA : float
:param PE: hypothetical probability of chance agreement (random accuracy)
:type PE : float
:param POP: population
:type POP:int
:return: kappa standard error as float
|
[
"Calculate",
"kappa",
"standard",
"error",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_overall_func.py#L591-L607
|
236,253
|
sepandhaghighi/pycm
|
pycm/pycm_overall_func.py
|
micro_calc
|
def micro_calc(TP, item):
"""
Calculate PPV_Micro and TPR_Micro.
:param TP: true positive
:type TP:dict
:param item: FN or FP
:type item : dict
:return: PPV_Micro or TPR_Micro as float
"""
try:
TP_sum = sum(TP.values())
item_sum = sum(item.values())
return TP_sum / (TP_sum + item_sum)
except Exception:
return "None"
|
python
|
def micro_calc(TP, item):
"""
Calculate PPV_Micro and TPR_Micro.
:param TP: true positive
:type TP:dict
:param item: FN or FP
:type item : dict
:return: PPV_Micro or TPR_Micro as float
"""
try:
TP_sum = sum(TP.values())
item_sum = sum(item.values())
return TP_sum / (TP_sum + item_sum)
except Exception:
return "None"
|
[
"def",
"micro_calc",
"(",
"TP",
",",
"item",
")",
":",
"try",
":",
"TP_sum",
"=",
"sum",
"(",
"TP",
".",
"values",
"(",
")",
")",
"item_sum",
"=",
"sum",
"(",
"item",
".",
"values",
"(",
")",
")",
"return",
"TP_sum",
"/",
"(",
"TP_sum",
"+",
"item_sum",
")",
"except",
"Exception",
":",
"return",
"\"None\""
] |
Calculate PPV_Micro and TPR_Micro.
:param TP: true positive
:type TP:dict
:param item: FN or FP
:type item : dict
:return: PPV_Micro or TPR_Micro as float
|
[
"Calculate",
"PPV_Micro",
"and",
"TPR_Micro",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_overall_func.py#L648-L663
|
236,254
|
sepandhaghighi/pycm
|
pycm/pycm_overall_func.py
|
macro_calc
|
def macro_calc(item):
"""
Calculate PPV_Macro and TPR_Macro.
:param item: PPV or TPR
:type item:dict
:return: PPV_Macro or TPR_Macro as float
"""
try:
item_sum = sum(item.values())
item_len = len(item.values())
return item_sum / item_len
except Exception:
return "None"
|
python
|
def macro_calc(item):
"""
Calculate PPV_Macro and TPR_Macro.
:param item: PPV or TPR
:type item:dict
:return: PPV_Macro or TPR_Macro as float
"""
try:
item_sum = sum(item.values())
item_len = len(item.values())
return item_sum / item_len
except Exception:
return "None"
|
[
"def",
"macro_calc",
"(",
"item",
")",
":",
"try",
":",
"item_sum",
"=",
"sum",
"(",
"item",
".",
"values",
"(",
")",
")",
"item_len",
"=",
"len",
"(",
"item",
".",
"values",
"(",
")",
")",
"return",
"item_sum",
"/",
"item_len",
"except",
"Exception",
":",
"return",
"\"None\""
] |
Calculate PPV_Macro and TPR_Macro.
:param item: PPV or TPR
:type item:dict
:return: PPV_Macro or TPR_Macro as float
|
[
"Calculate",
"PPV_Macro",
"and",
"TPR_Macro",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_overall_func.py#L666-L679
|
236,255
|
sepandhaghighi/pycm
|
pycm/pycm_overall_func.py
|
PC_PI_calc
|
def PC_PI_calc(P, TOP, POP):
"""
Calculate percent chance agreement for Scott's Pi.
:param P: condition positive
:type P : dict
:param TOP: test outcome positive
:type TOP : dict
:param POP: population
:type POP:dict
:return: percent chance agreement as float
"""
try:
result = 0
for i in P.keys():
result += ((P[i] + TOP[i]) / (2 * POP[i]))**2
return result
except Exception:
return "None"
|
python
|
def PC_PI_calc(P, TOP, POP):
"""
Calculate percent chance agreement for Scott's Pi.
:param P: condition positive
:type P : dict
:param TOP: test outcome positive
:type TOP : dict
:param POP: population
:type POP:dict
:return: percent chance agreement as float
"""
try:
result = 0
for i in P.keys():
result += ((P[i] + TOP[i]) / (2 * POP[i]))**2
return result
except Exception:
return "None"
|
[
"def",
"PC_PI_calc",
"(",
"P",
",",
"TOP",
",",
"POP",
")",
":",
"try",
":",
"result",
"=",
"0",
"for",
"i",
"in",
"P",
".",
"keys",
"(",
")",
":",
"result",
"+=",
"(",
"(",
"P",
"[",
"i",
"]",
"+",
"TOP",
"[",
"i",
"]",
")",
"/",
"(",
"2",
"*",
"POP",
"[",
"i",
"]",
")",
")",
"**",
"2",
"return",
"result",
"except",
"Exception",
":",
"return",
"\"None\""
] |
Calculate percent chance agreement for Scott's Pi.
:param P: condition positive
:type P : dict
:param TOP: test outcome positive
:type TOP : dict
:param POP: population
:type POP:dict
:return: percent chance agreement as float
|
[
"Calculate",
"percent",
"chance",
"agreement",
"for",
"Scott",
"s",
"Pi",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_overall_func.py#L682-L700
|
236,256
|
sepandhaghighi/pycm
|
pycm/pycm_overall_func.py
|
PC_AC1_calc
|
def PC_AC1_calc(P, TOP, POP):
"""
Calculate percent chance agreement for Gwet's AC1.
:param P: condition positive
:type P : dict
:param TOP: test outcome positive
:type TOP : dict
:param POP: population
:type POP:dict
:return: percent chance agreement as float
"""
try:
result = 0
classes = list(P.keys())
for i in classes:
pi = ((P[i] + TOP[i]) / (2 * POP[i]))
result += pi * (1 - pi)
result = result / (len(classes) - 1)
return result
except Exception:
return "None"
|
python
|
def PC_AC1_calc(P, TOP, POP):
"""
Calculate percent chance agreement for Gwet's AC1.
:param P: condition positive
:type P : dict
:param TOP: test outcome positive
:type TOP : dict
:param POP: population
:type POP:dict
:return: percent chance agreement as float
"""
try:
result = 0
classes = list(P.keys())
for i in classes:
pi = ((P[i] + TOP[i]) / (2 * POP[i]))
result += pi * (1 - pi)
result = result / (len(classes) - 1)
return result
except Exception:
return "None"
|
[
"def",
"PC_AC1_calc",
"(",
"P",
",",
"TOP",
",",
"POP",
")",
":",
"try",
":",
"result",
"=",
"0",
"classes",
"=",
"list",
"(",
"P",
".",
"keys",
"(",
")",
")",
"for",
"i",
"in",
"classes",
":",
"pi",
"=",
"(",
"(",
"P",
"[",
"i",
"]",
"+",
"TOP",
"[",
"i",
"]",
")",
"/",
"(",
"2",
"*",
"POP",
"[",
"i",
"]",
")",
")",
"result",
"+=",
"pi",
"*",
"(",
"1",
"-",
"pi",
")",
"result",
"=",
"result",
"/",
"(",
"len",
"(",
"classes",
")",
"-",
"1",
")",
"return",
"result",
"except",
"Exception",
":",
"return",
"\"None\""
] |
Calculate percent chance agreement for Gwet's AC1.
:param P: condition positive
:type P : dict
:param TOP: test outcome positive
:type TOP : dict
:param POP: population
:type POP:dict
:return: percent chance agreement as float
|
[
"Calculate",
"percent",
"chance",
"agreement",
"for",
"Gwet",
"s",
"AC1",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_overall_func.py#L703-L724
|
236,257
|
sepandhaghighi/pycm
|
pycm/pycm_overall_func.py
|
overall_jaccard_index_calc
|
def overall_jaccard_index_calc(jaccard_list):
"""
Calculate overall jaccard index.
:param jaccard_list : list of jaccard index for each class
:type jaccard_list : list
:return: (jaccard_sum , jaccard_mean) as tuple
"""
try:
jaccard_sum = sum(jaccard_list)
jaccard_mean = jaccard_sum / len(jaccard_list)
return (jaccard_sum, jaccard_mean)
except Exception:
return "None"
|
python
|
def overall_jaccard_index_calc(jaccard_list):
"""
Calculate overall jaccard index.
:param jaccard_list : list of jaccard index for each class
:type jaccard_list : list
:return: (jaccard_sum , jaccard_mean) as tuple
"""
try:
jaccard_sum = sum(jaccard_list)
jaccard_mean = jaccard_sum / len(jaccard_list)
return (jaccard_sum, jaccard_mean)
except Exception:
return "None"
|
[
"def",
"overall_jaccard_index_calc",
"(",
"jaccard_list",
")",
":",
"try",
":",
"jaccard_sum",
"=",
"sum",
"(",
"jaccard_list",
")",
"jaccard_mean",
"=",
"jaccard_sum",
"/",
"len",
"(",
"jaccard_list",
")",
"return",
"(",
"jaccard_sum",
",",
"jaccard_mean",
")",
"except",
"Exception",
":",
"return",
"\"None\""
] |
Calculate overall jaccard index.
:param jaccard_list : list of jaccard index for each class
:type jaccard_list : list
:return: (jaccard_sum , jaccard_mean) as tuple
|
[
"Calculate",
"overall",
"jaccard",
"index",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_overall_func.py#L741-L754
|
236,258
|
sepandhaghighi/pycm
|
pycm/pycm_overall_func.py
|
overall_accuracy_calc
|
def overall_accuracy_calc(TP, POP):
"""
Calculate overall accuracy.
:param TP: true positive
:type TP : dict
:param POP: population
:type POP:int
:return: overall_accuracy as float
"""
try:
overall_accuracy = sum(TP.values()) / POP
return overall_accuracy
except Exception:
return "None"
|
python
|
def overall_accuracy_calc(TP, POP):
"""
Calculate overall accuracy.
:param TP: true positive
:type TP : dict
:param POP: population
:type POP:int
:return: overall_accuracy as float
"""
try:
overall_accuracy = sum(TP.values()) / POP
return overall_accuracy
except Exception:
return "None"
|
[
"def",
"overall_accuracy_calc",
"(",
"TP",
",",
"POP",
")",
":",
"try",
":",
"overall_accuracy",
"=",
"sum",
"(",
"TP",
".",
"values",
"(",
")",
")",
"/",
"POP",
"return",
"overall_accuracy",
"except",
"Exception",
":",
"return",
"\"None\""
] |
Calculate overall accuracy.
:param TP: true positive
:type TP : dict
:param POP: population
:type POP:int
:return: overall_accuracy as float
|
[
"Calculate",
"overall",
"accuracy",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_overall_func.py#L757-L771
|
236,259
|
sepandhaghighi/pycm
|
pycm/pycm_interpret.py
|
AUC_analysis
|
def AUC_analysis(AUC):
"""
Analysis AUC with interpretation table.
:param AUC: area under the ROC curve
:type AUC : float
:return: interpretation result as str
"""
try:
if AUC == "None":
return "None"
if AUC < 0.6:
return "Poor"
if AUC >= 0.6 and AUC < 0.7:
return "Fair"
if AUC >= 0.7 and AUC < 0.8:
return "Good"
if AUC >= 0.8 and AUC < 0.9:
return "Very Good"
return "Excellent"
except Exception: # pragma: no cover
return "None"
|
python
|
def AUC_analysis(AUC):
"""
Analysis AUC with interpretation table.
:param AUC: area under the ROC curve
:type AUC : float
:return: interpretation result as str
"""
try:
if AUC == "None":
return "None"
if AUC < 0.6:
return "Poor"
if AUC >= 0.6 and AUC < 0.7:
return "Fair"
if AUC >= 0.7 and AUC < 0.8:
return "Good"
if AUC >= 0.8 and AUC < 0.9:
return "Very Good"
return "Excellent"
except Exception: # pragma: no cover
return "None"
|
[
"def",
"AUC_analysis",
"(",
"AUC",
")",
":",
"try",
":",
"if",
"AUC",
"==",
"\"None\"",
":",
"return",
"\"None\"",
"if",
"AUC",
"<",
"0.6",
":",
"return",
"\"Poor\"",
"if",
"AUC",
">=",
"0.6",
"and",
"AUC",
"<",
"0.7",
":",
"return",
"\"Fair\"",
"if",
"AUC",
">=",
"0.7",
"and",
"AUC",
"<",
"0.8",
":",
"return",
"\"Good\"",
"if",
"AUC",
">=",
"0.8",
"and",
"AUC",
"<",
"0.9",
":",
"return",
"\"Very Good\"",
"return",
"\"Excellent\"",
"except",
"Exception",
":",
"# pragma: no cover",
"return",
"\"None\""
] |
Analysis AUC with interpretation table.
:param AUC: area under the ROC curve
:type AUC : float
:return: interpretation result as str
|
[
"Analysis",
"AUC",
"with",
"interpretation",
"table",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_interpret.py#L50-L71
|
236,260
|
sepandhaghighi/pycm
|
pycm/pycm_interpret.py
|
kappa_analysis_cicchetti
|
def kappa_analysis_cicchetti(kappa):
"""
Analysis kappa number with Cicchetti benchmark.
:param kappa: kappa number
:type kappa : float
:return: strength of agreement as str
"""
try:
if kappa < 0.4:
return "Poor"
if kappa >= 0.4 and kappa < 0.59:
return "Fair"
if kappa >= 0.59 and kappa < 0.74:
return "Good"
if kappa >= 0.74 and kappa <= 1:
return "Excellent"
return "None"
except Exception: # pragma: no cover
return "None"
|
python
|
def kappa_analysis_cicchetti(kappa):
"""
Analysis kappa number with Cicchetti benchmark.
:param kappa: kappa number
:type kappa : float
:return: strength of agreement as str
"""
try:
if kappa < 0.4:
return "Poor"
if kappa >= 0.4 and kappa < 0.59:
return "Fair"
if kappa >= 0.59 and kappa < 0.74:
return "Good"
if kappa >= 0.74 and kappa <= 1:
return "Excellent"
return "None"
except Exception: # pragma: no cover
return "None"
|
[
"def",
"kappa_analysis_cicchetti",
"(",
"kappa",
")",
":",
"try",
":",
"if",
"kappa",
"<",
"0.4",
":",
"return",
"\"Poor\"",
"if",
"kappa",
">=",
"0.4",
"and",
"kappa",
"<",
"0.59",
":",
"return",
"\"Fair\"",
"if",
"kappa",
">=",
"0.59",
"and",
"kappa",
"<",
"0.74",
":",
"return",
"\"Good\"",
"if",
"kappa",
">=",
"0.74",
"and",
"kappa",
"<=",
"1",
":",
"return",
"\"Excellent\"",
"return",
"\"None\"",
"except",
"Exception",
":",
"# pragma: no cover",
"return",
"\"None\""
] |
Analysis kappa number with Cicchetti benchmark.
:param kappa: kappa number
:type kappa : float
:return: strength of agreement as str
|
[
"Analysis",
"kappa",
"number",
"with",
"Cicchetti",
"benchmark",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_interpret.py#L74-L93
|
236,261
|
sepandhaghighi/pycm
|
pycm/pycm_interpret.py
|
kappa_analysis_koch
|
def kappa_analysis_koch(kappa):
"""
Analysis kappa number with Landis-Koch benchmark.
:param kappa: kappa number
:type kappa : float
:return: strength of agreement as str
"""
try:
if kappa < 0:
return "Poor"
if kappa >= 0 and kappa < 0.2:
return "Slight"
if kappa >= 0.20 and kappa < 0.4:
return "Fair"
if kappa >= 0.40 and kappa < 0.6:
return "Moderate"
if kappa >= 0.60 and kappa < 0.8:
return "Substantial"
if kappa >= 0.80 and kappa <= 1:
return "Almost Perfect"
return "None"
except Exception: # pragma: no cover
return "None"
|
python
|
def kappa_analysis_koch(kappa):
"""
Analysis kappa number with Landis-Koch benchmark.
:param kappa: kappa number
:type kappa : float
:return: strength of agreement as str
"""
try:
if kappa < 0:
return "Poor"
if kappa >= 0 and kappa < 0.2:
return "Slight"
if kappa >= 0.20 and kappa < 0.4:
return "Fair"
if kappa >= 0.40 and kappa < 0.6:
return "Moderate"
if kappa >= 0.60 and kappa < 0.8:
return "Substantial"
if kappa >= 0.80 and kappa <= 1:
return "Almost Perfect"
return "None"
except Exception: # pragma: no cover
return "None"
|
[
"def",
"kappa_analysis_koch",
"(",
"kappa",
")",
":",
"try",
":",
"if",
"kappa",
"<",
"0",
":",
"return",
"\"Poor\"",
"if",
"kappa",
">=",
"0",
"and",
"kappa",
"<",
"0.2",
":",
"return",
"\"Slight\"",
"if",
"kappa",
">=",
"0.20",
"and",
"kappa",
"<",
"0.4",
":",
"return",
"\"Fair\"",
"if",
"kappa",
">=",
"0.40",
"and",
"kappa",
"<",
"0.6",
":",
"return",
"\"Moderate\"",
"if",
"kappa",
">=",
"0.60",
"and",
"kappa",
"<",
"0.8",
":",
"return",
"\"Substantial\"",
"if",
"kappa",
">=",
"0.80",
"and",
"kappa",
"<=",
"1",
":",
"return",
"\"Almost Perfect\"",
"return",
"\"None\"",
"except",
"Exception",
":",
"# pragma: no cover",
"return",
"\"None\""
] |
Analysis kappa number with Landis-Koch benchmark.
:param kappa: kappa number
:type kappa : float
:return: strength of agreement as str
|
[
"Analysis",
"kappa",
"number",
"with",
"Landis",
"-",
"Koch",
"benchmark",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_interpret.py#L96-L119
|
236,262
|
sepandhaghighi/pycm
|
pycm/pycm_interpret.py
|
kappa_analysis_altman
|
def kappa_analysis_altman(kappa):
"""
Analysis kappa number with Altman benchmark.
:param kappa: kappa number
:type kappa : float
:return: strength of agreement as str
"""
try:
if kappa < 0.2:
return "Poor"
if kappa >= 0.20 and kappa < 0.4:
return "Fair"
if kappa >= 0.40 and kappa < 0.6:
return "Moderate"
if kappa >= 0.60 and kappa < 0.8:
return "Good"
if kappa >= 0.80 and kappa <= 1:
return "Very Good"
return "None"
except Exception: # pragma: no cover
return "None"
|
python
|
def kappa_analysis_altman(kappa):
"""
Analysis kappa number with Altman benchmark.
:param kappa: kappa number
:type kappa : float
:return: strength of agreement as str
"""
try:
if kappa < 0.2:
return "Poor"
if kappa >= 0.20 and kappa < 0.4:
return "Fair"
if kappa >= 0.40 and kappa < 0.6:
return "Moderate"
if kappa >= 0.60 and kappa < 0.8:
return "Good"
if kappa >= 0.80 and kappa <= 1:
return "Very Good"
return "None"
except Exception: # pragma: no cover
return "None"
|
[
"def",
"kappa_analysis_altman",
"(",
"kappa",
")",
":",
"try",
":",
"if",
"kappa",
"<",
"0.2",
":",
"return",
"\"Poor\"",
"if",
"kappa",
">=",
"0.20",
"and",
"kappa",
"<",
"0.4",
":",
"return",
"\"Fair\"",
"if",
"kappa",
">=",
"0.40",
"and",
"kappa",
"<",
"0.6",
":",
"return",
"\"Moderate\"",
"if",
"kappa",
">=",
"0.60",
"and",
"kappa",
"<",
"0.8",
":",
"return",
"\"Good\"",
"if",
"kappa",
">=",
"0.80",
"and",
"kappa",
"<=",
"1",
":",
"return",
"\"Very Good\"",
"return",
"\"None\"",
"except",
"Exception",
":",
"# pragma: no cover",
"return",
"\"None\""
] |
Analysis kappa number with Altman benchmark.
:param kappa: kappa number
:type kappa : float
:return: strength of agreement as str
|
[
"Analysis",
"kappa",
"number",
"with",
"Altman",
"benchmark",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_interpret.py#L141-L162
|
236,263
|
sepandhaghighi/pycm
|
setup.py
|
get_requires
|
def get_requires():
"""Read requirements.txt."""
requirements = open("requirements.txt", "r").read()
return list(filter(lambda x: x != "", requirements.split()))
|
python
|
def get_requires():
"""Read requirements.txt."""
requirements = open("requirements.txt", "r").read()
return list(filter(lambda x: x != "", requirements.split()))
|
[
"def",
"get_requires",
"(",
")",
":",
"requirements",
"=",
"open",
"(",
"\"requirements.txt\"",
",",
"\"r\"",
")",
".",
"read",
"(",
")",
"return",
"list",
"(",
"filter",
"(",
"lambda",
"x",
":",
"x",
"!=",
"\"\"",
",",
"requirements",
".",
"split",
"(",
")",
")",
")"
] |
Read requirements.txt.
|
[
"Read",
"requirements",
".",
"txt",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/setup.py#L9-L12
|
236,264
|
sepandhaghighi/pycm
|
setup.py
|
read_description
|
def read_description():
"""Read README.md and CHANGELOG.md."""
try:
with open("README.md") as r:
description = "\n"
description += r.read()
with open("CHANGELOG.md") as c:
description += "\n"
description += c.read()
return description
except Exception:
return '''
PyCM is a multi-class confusion matrix library written in Python that
supports both input data vectors and direct matrix, and a proper tool for
post-classification model evaluation that supports most classes and overall
statistics parameters.
PyCM is the swiss-army knife of confusion matrices, targeted mainly at
data scientists that need a broad array of metrics for predictive models
and an accurate evaluation of large variety of classifiers.'''
|
python
|
def read_description():
"""Read README.md and CHANGELOG.md."""
try:
with open("README.md") as r:
description = "\n"
description += r.read()
with open("CHANGELOG.md") as c:
description += "\n"
description += c.read()
return description
except Exception:
return '''
PyCM is a multi-class confusion matrix library written in Python that
supports both input data vectors and direct matrix, and a proper tool for
post-classification model evaluation that supports most classes and overall
statistics parameters.
PyCM is the swiss-army knife of confusion matrices, targeted mainly at
data scientists that need a broad array of metrics for predictive models
and an accurate evaluation of large variety of classifiers.'''
|
[
"def",
"read_description",
"(",
")",
":",
"try",
":",
"with",
"open",
"(",
"\"README.md\"",
")",
"as",
"r",
":",
"description",
"=",
"\"\\n\"",
"description",
"+=",
"r",
".",
"read",
"(",
")",
"with",
"open",
"(",
"\"CHANGELOG.md\"",
")",
"as",
"c",
":",
"description",
"+=",
"\"\\n\"",
"description",
"+=",
"c",
".",
"read",
"(",
")",
"return",
"description",
"except",
"Exception",
":",
"return",
"'''\n PyCM is a multi-class confusion matrix library written in Python that\n supports both input data vectors and direct matrix, and a proper tool for\n post-classification model evaluation that supports most classes and overall\n statistics parameters.\n PyCM is the swiss-army knife of confusion matrices, targeted mainly at\n data scientists that need a broad array of metrics for predictive models\n and an accurate evaluation of large variety of classifiers.'''"
] |
Read README.md and CHANGELOG.md.
|
[
"Read",
"README",
".",
"md",
"and",
"CHANGELOG",
".",
"md",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/setup.py#L15-L33
|
236,265
|
sepandhaghighi/pycm
|
pycm/pycm_obj.py
|
ConfusionMatrix.print_matrix
|
def print_matrix(self, one_vs_all=False, class_name=None):
"""
Print confusion matrix.
:param one_vs_all : One-Vs-All mode flag
:type one_vs_all : bool
:param class_name : target class name for One-Vs-All mode
:type class_name : any valid type
:return: None
"""
classes = self.classes
table = self.table
if one_vs_all:
[classes, table] = one_vs_all_func(
classes, table, self.TP, self.TN, self.FP, self.FN, class_name)
print(table_print(classes, table))
|
python
|
def print_matrix(self, one_vs_all=False, class_name=None):
"""
Print confusion matrix.
:param one_vs_all : One-Vs-All mode flag
:type one_vs_all : bool
:param class_name : target class name for One-Vs-All mode
:type class_name : any valid type
:return: None
"""
classes = self.classes
table = self.table
if one_vs_all:
[classes, table] = one_vs_all_func(
classes, table, self.TP, self.TN, self.FP, self.FN, class_name)
print(table_print(classes, table))
|
[
"def",
"print_matrix",
"(",
"self",
",",
"one_vs_all",
"=",
"False",
",",
"class_name",
"=",
"None",
")",
":",
"classes",
"=",
"self",
".",
"classes",
"table",
"=",
"self",
".",
"table",
"if",
"one_vs_all",
":",
"[",
"classes",
",",
"table",
"]",
"=",
"one_vs_all_func",
"(",
"classes",
",",
"table",
",",
"self",
".",
"TP",
",",
"self",
".",
"TN",
",",
"self",
".",
"FP",
",",
"self",
".",
"FN",
",",
"class_name",
")",
"print",
"(",
"table_print",
"(",
"classes",
",",
"table",
")",
")"
] |
Print confusion matrix.
:param one_vs_all : One-Vs-All mode flag
:type one_vs_all : bool
:param class_name : target class name for One-Vs-All mode
:type class_name : any valid type
:return: None
|
[
"Print",
"confusion",
"matrix",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_obj.py#L94-L109
|
236,266
|
sepandhaghighi/pycm
|
pycm/pycm_obj.py
|
ConfusionMatrix.stat
|
def stat(self, overall_param=None, class_param=None, class_name=None):
"""
Print statistical measures table.
:param overall_param : overall parameters list for print, Example : ["Kappa","Scott PI]
:type overall_param : list
:param class_param : class parameters list for print, Example : ["TPR","TNR","AUC"]
:type class_param : list
:param class_name : class name (sub set of classes), Example :[1,2,3]
:type class_name : list
:return: None
"""
classes = class_filter(self.classes, class_name)
print(
stat_print(
classes,
self.class_stat,
self.overall_stat,
self.digit, overall_param, class_param))
|
python
|
def stat(self, overall_param=None, class_param=None, class_name=None):
"""
Print statistical measures table.
:param overall_param : overall parameters list for print, Example : ["Kappa","Scott PI]
:type overall_param : list
:param class_param : class parameters list for print, Example : ["TPR","TNR","AUC"]
:type class_param : list
:param class_name : class name (sub set of classes), Example :[1,2,3]
:type class_name : list
:return: None
"""
classes = class_filter(self.classes, class_name)
print(
stat_print(
classes,
self.class_stat,
self.overall_stat,
self.digit, overall_param, class_param))
|
[
"def",
"stat",
"(",
"self",
",",
"overall_param",
"=",
"None",
",",
"class_param",
"=",
"None",
",",
"class_name",
"=",
"None",
")",
":",
"classes",
"=",
"class_filter",
"(",
"self",
".",
"classes",
",",
"class_name",
")",
"print",
"(",
"stat_print",
"(",
"classes",
",",
"self",
".",
"class_stat",
",",
"self",
".",
"overall_stat",
",",
"self",
".",
"digit",
",",
"overall_param",
",",
"class_param",
")",
")"
] |
Print statistical measures table.
:param overall_param : overall parameters list for print, Example : ["Kappa","Scott PI]
:type overall_param : list
:param class_param : class parameters list for print, Example : ["TPR","TNR","AUC"]
:type class_param : list
:param class_name : class name (sub set of classes), Example :[1,2,3]
:type class_name : list
:return: None
|
[
"Print",
"statistical",
"measures",
"table",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_obj.py#L129-L147
|
236,267
|
sepandhaghighi/pycm
|
pycm/pycm_obj.py
|
ConfusionMatrix.save_html
|
def save_html(
self,
name,
address=True,
overall_param=None,
class_param=None,
class_name=None, color=(0, 0, 0), normalize=False):
"""
Save ConfusionMatrix in HTML file.
:param name: filename
:type name : str
:param address: flag for address return
:type address : bool
:param overall_param : overall parameters list for save, Example : ["Kappa","Scott PI]
:type overall_param : list
:param class_param : class parameters list for save, Example : ["TPR","TNR","AUC"]
:type class_param : list
:param class_name : class name (sub set of classes), Example :[1,2,3]
:type class_name : list
:param color : matrix color (R,G,B)
:type color : tuple
:param normalize : save normalize matrix flag
:type normalize : bool
:return: saving Status as dict {"Status":bool , "Message":str}
"""
try:
message = None
table = self.table
if normalize:
table = self.normalized_table
html_file = open(name + ".html", "w")
html_file.write(html_init(name))
html_file.write(html_dataset_type(self.binary, self.imbalance))
html_file.write(html_table(self.classes, table, color, normalize))
html_file.write(
html_overall_stat(
self.overall_stat,
self.digit,
overall_param,
self.recommended_list))
class_stat_classes = class_filter(self.classes, class_name)
html_file.write(
html_class_stat(
class_stat_classes,
self.class_stat,
self.digit,
class_param,
self.recommended_list))
html_file.write(html_end(VERSION))
html_file.close()
if address:
message = os.path.join(os.getcwd(), name + ".html")
return {"Status": True, "Message": message}
except Exception as e:
return {"Status": False, "Message": str(e)}
|
python
|
def save_html(
self,
name,
address=True,
overall_param=None,
class_param=None,
class_name=None, color=(0, 0, 0), normalize=False):
"""
Save ConfusionMatrix in HTML file.
:param name: filename
:type name : str
:param address: flag for address return
:type address : bool
:param overall_param : overall parameters list for save, Example : ["Kappa","Scott PI]
:type overall_param : list
:param class_param : class parameters list for save, Example : ["TPR","TNR","AUC"]
:type class_param : list
:param class_name : class name (sub set of classes), Example :[1,2,3]
:type class_name : list
:param color : matrix color (R,G,B)
:type color : tuple
:param normalize : save normalize matrix flag
:type normalize : bool
:return: saving Status as dict {"Status":bool , "Message":str}
"""
try:
message = None
table = self.table
if normalize:
table = self.normalized_table
html_file = open(name + ".html", "w")
html_file.write(html_init(name))
html_file.write(html_dataset_type(self.binary, self.imbalance))
html_file.write(html_table(self.classes, table, color, normalize))
html_file.write(
html_overall_stat(
self.overall_stat,
self.digit,
overall_param,
self.recommended_list))
class_stat_classes = class_filter(self.classes, class_name)
html_file.write(
html_class_stat(
class_stat_classes,
self.class_stat,
self.digit,
class_param,
self.recommended_list))
html_file.write(html_end(VERSION))
html_file.close()
if address:
message = os.path.join(os.getcwd(), name + ".html")
return {"Status": True, "Message": message}
except Exception as e:
return {"Status": False, "Message": str(e)}
|
[
"def",
"save_html",
"(",
"self",
",",
"name",
",",
"address",
"=",
"True",
",",
"overall_param",
"=",
"None",
",",
"class_param",
"=",
"None",
",",
"class_name",
"=",
"None",
",",
"color",
"=",
"(",
"0",
",",
"0",
",",
"0",
")",
",",
"normalize",
"=",
"False",
")",
":",
"try",
":",
"message",
"=",
"None",
"table",
"=",
"self",
".",
"table",
"if",
"normalize",
":",
"table",
"=",
"self",
".",
"normalized_table",
"html_file",
"=",
"open",
"(",
"name",
"+",
"\".html\"",
",",
"\"w\"",
")",
"html_file",
".",
"write",
"(",
"html_init",
"(",
"name",
")",
")",
"html_file",
".",
"write",
"(",
"html_dataset_type",
"(",
"self",
".",
"binary",
",",
"self",
".",
"imbalance",
")",
")",
"html_file",
".",
"write",
"(",
"html_table",
"(",
"self",
".",
"classes",
",",
"table",
",",
"color",
",",
"normalize",
")",
")",
"html_file",
".",
"write",
"(",
"html_overall_stat",
"(",
"self",
".",
"overall_stat",
",",
"self",
".",
"digit",
",",
"overall_param",
",",
"self",
".",
"recommended_list",
")",
")",
"class_stat_classes",
"=",
"class_filter",
"(",
"self",
".",
"classes",
",",
"class_name",
")",
"html_file",
".",
"write",
"(",
"html_class_stat",
"(",
"class_stat_classes",
",",
"self",
".",
"class_stat",
",",
"self",
".",
"digit",
",",
"class_param",
",",
"self",
".",
"recommended_list",
")",
")",
"html_file",
".",
"write",
"(",
"html_end",
"(",
"VERSION",
")",
")",
"html_file",
".",
"close",
"(",
")",
"if",
"address",
":",
"message",
"=",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"getcwd",
"(",
")",
",",
"name",
"+",
"\".html\"",
")",
"return",
"{",
"\"Status\"",
":",
"True",
",",
"\"Message\"",
":",
"message",
"}",
"except",
"Exception",
"as",
"e",
":",
"return",
"{",
"\"Status\"",
":",
"False",
",",
"\"Message\"",
":",
"str",
"(",
"e",
")",
"}"
] |
Save ConfusionMatrix in HTML file.
:param name: filename
:type name : str
:param address: flag for address return
:type address : bool
:param overall_param : overall parameters list for save, Example : ["Kappa","Scott PI]
:type overall_param : list
:param class_param : class parameters list for save, Example : ["TPR","TNR","AUC"]
:type class_param : list
:param class_name : class name (sub set of classes), Example :[1,2,3]
:type class_name : list
:param color : matrix color (R,G,B)
:type color : tuple
:param normalize : save normalize matrix flag
:type normalize : bool
:return: saving Status as dict {"Status":bool , "Message":str}
|
[
"Save",
"ConfusionMatrix",
"in",
"HTML",
"file",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_obj.py#L212-L267
|
236,268
|
sepandhaghighi/pycm
|
pycm/pycm_obj.py
|
ConfusionMatrix.save_csv
|
def save_csv(
self,
name,
address=True,
class_param=None,
class_name=None,
matrix_save=True,
normalize=False):
"""
Save ConfusionMatrix in CSV file.
:param name: filename
:type name : str
:param address: flag for address return
:type address : bool
:param class_param : class parameters list for save, Example : ["TPR","TNR","AUC"]
:type class_param : list
:param class_name : class name (sub set of classes), Example :[1,2,3]
:type class_name : list
:param matrix_save : save matrix flag
:type matrix_save : bool
:param normalize : save normalize matrix flag
:type normalize : bool
:return: saving Status as dict {"Status":bool , "Message":str}
"""
try:
message = None
classes = class_filter(self.classes, class_name)
csv_file = open(name + ".csv", "w")
csv_data = csv_print(
classes,
self.class_stat,
self.digit,
class_param)
csv_file.write(csv_data)
if matrix_save:
matrix = self.table
if normalize:
matrix = self.normalized_table
csv_matrix_file = open(name + "_matrix" + ".csv", "w")
csv_matrix_data = csv_matrix_print(self.classes, matrix)
csv_matrix_file.write(csv_matrix_data)
if address:
message = os.path.join(os.getcwd(), name + ".csv")
return {"Status": True, "Message": message}
except Exception as e:
return {"Status": False, "Message": str(e)}
|
python
|
def save_csv(
self,
name,
address=True,
class_param=None,
class_name=None,
matrix_save=True,
normalize=False):
"""
Save ConfusionMatrix in CSV file.
:param name: filename
:type name : str
:param address: flag for address return
:type address : bool
:param class_param : class parameters list for save, Example : ["TPR","TNR","AUC"]
:type class_param : list
:param class_name : class name (sub set of classes), Example :[1,2,3]
:type class_name : list
:param matrix_save : save matrix flag
:type matrix_save : bool
:param normalize : save normalize matrix flag
:type normalize : bool
:return: saving Status as dict {"Status":bool , "Message":str}
"""
try:
message = None
classes = class_filter(self.classes, class_name)
csv_file = open(name + ".csv", "w")
csv_data = csv_print(
classes,
self.class_stat,
self.digit,
class_param)
csv_file.write(csv_data)
if matrix_save:
matrix = self.table
if normalize:
matrix = self.normalized_table
csv_matrix_file = open(name + "_matrix" + ".csv", "w")
csv_matrix_data = csv_matrix_print(self.classes, matrix)
csv_matrix_file.write(csv_matrix_data)
if address:
message = os.path.join(os.getcwd(), name + ".csv")
return {"Status": True, "Message": message}
except Exception as e:
return {"Status": False, "Message": str(e)}
|
[
"def",
"save_csv",
"(",
"self",
",",
"name",
",",
"address",
"=",
"True",
",",
"class_param",
"=",
"None",
",",
"class_name",
"=",
"None",
",",
"matrix_save",
"=",
"True",
",",
"normalize",
"=",
"False",
")",
":",
"try",
":",
"message",
"=",
"None",
"classes",
"=",
"class_filter",
"(",
"self",
".",
"classes",
",",
"class_name",
")",
"csv_file",
"=",
"open",
"(",
"name",
"+",
"\".csv\"",
",",
"\"w\"",
")",
"csv_data",
"=",
"csv_print",
"(",
"classes",
",",
"self",
".",
"class_stat",
",",
"self",
".",
"digit",
",",
"class_param",
")",
"csv_file",
".",
"write",
"(",
"csv_data",
")",
"if",
"matrix_save",
":",
"matrix",
"=",
"self",
".",
"table",
"if",
"normalize",
":",
"matrix",
"=",
"self",
".",
"normalized_table",
"csv_matrix_file",
"=",
"open",
"(",
"name",
"+",
"\"_matrix\"",
"+",
"\".csv\"",
",",
"\"w\"",
")",
"csv_matrix_data",
"=",
"csv_matrix_print",
"(",
"self",
".",
"classes",
",",
"matrix",
")",
"csv_matrix_file",
".",
"write",
"(",
"csv_matrix_data",
")",
"if",
"address",
":",
"message",
"=",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"getcwd",
"(",
")",
",",
"name",
"+",
"\".csv\"",
")",
"return",
"{",
"\"Status\"",
":",
"True",
",",
"\"Message\"",
":",
"message",
"}",
"except",
"Exception",
"as",
"e",
":",
"return",
"{",
"\"Status\"",
":",
"False",
",",
"\"Message\"",
":",
"str",
"(",
"e",
")",
"}"
] |
Save ConfusionMatrix in CSV file.
:param name: filename
:type name : str
:param address: flag for address return
:type address : bool
:param class_param : class parameters list for save, Example : ["TPR","TNR","AUC"]
:type class_param : list
:param class_name : class name (sub set of classes), Example :[1,2,3]
:type class_name : list
:param matrix_save : save matrix flag
:type matrix_save : bool
:param normalize : save normalize matrix flag
:type normalize : bool
:return: saving Status as dict {"Status":bool , "Message":str}
|
[
"Save",
"ConfusionMatrix",
"in",
"CSV",
"file",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_obj.py#L269-L315
|
236,269
|
sepandhaghighi/pycm
|
pycm/pycm_obj.py
|
ConfusionMatrix.save_obj
|
def save_obj(self, name, address=True):
"""
Save ConfusionMatrix in .obj file.
:param name: filename
:type name : str
:param address: flag for address return
:type address : bool
:return: saving Status as dict {"Status":bool , "Message":str}
"""
try:
message = None
obj_file = open(name + ".obj", "w")
actual_vector_temp = self.actual_vector
predict_vector_temp = self.predict_vector
matrix_temp = {k: self.table[k].copy() for k in self.classes}
matrix_items = []
for i in self.classes:
matrix_items.append((i, list(matrix_temp[i].items())))
if isinstance(actual_vector_temp, numpy.ndarray):
actual_vector_temp = actual_vector_temp.tolist()
if isinstance(predict_vector_temp, numpy.ndarray):
predict_vector_temp = predict_vector_temp.tolist()
json.dump({"Actual-Vector": actual_vector_temp,
"Predict-Vector": predict_vector_temp,
"Matrix": matrix_items,
"Digit": self.digit,
"Sample-Weight": self.weights,
"Transpose": self.transpose}, obj_file)
if address:
message = os.path.join(os.getcwd(), name + ".obj")
return {"Status": True, "Message": message}
except Exception as e:
return {"Status": False, "Message": str(e)}
|
python
|
def save_obj(self, name, address=True):
"""
Save ConfusionMatrix in .obj file.
:param name: filename
:type name : str
:param address: flag for address return
:type address : bool
:return: saving Status as dict {"Status":bool , "Message":str}
"""
try:
message = None
obj_file = open(name + ".obj", "w")
actual_vector_temp = self.actual_vector
predict_vector_temp = self.predict_vector
matrix_temp = {k: self.table[k].copy() for k in self.classes}
matrix_items = []
for i in self.classes:
matrix_items.append((i, list(matrix_temp[i].items())))
if isinstance(actual_vector_temp, numpy.ndarray):
actual_vector_temp = actual_vector_temp.tolist()
if isinstance(predict_vector_temp, numpy.ndarray):
predict_vector_temp = predict_vector_temp.tolist()
json.dump({"Actual-Vector": actual_vector_temp,
"Predict-Vector": predict_vector_temp,
"Matrix": matrix_items,
"Digit": self.digit,
"Sample-Weight": self.weights,
"Transpose": self.transpose}, obj_file)
if address:
message = os.path.join(os.getcwd(), name + ".obj")
return {"Status": True, "Message": message}
except Exception as e:
return {"Status": False, "Message": str(e)}
|
[
"def",
"save_obj",
"(",
"self",
",",
"name",
",",
"address",
"=",
"True",
")",
":",
"try",
":",
"message",
"=",
"None",
"obj_file",
"=",
"open",
"(",
"name",
"+",
"\".obj\"",
",",
"\"w\"",
")",
"actual_vector_temp",
"=",
"self",
".",
"actual_vector",
"predict_vector_temp",
"=",
"self",
".",
"predict_vector",
"matrix_temp",
"=",
"{",
"k",
":",
"self",
".",
"table",
"[",
"k",
"]",
".",
"copy",
"(",
")",
"for",
"k",
"in",
"self",
".",
"classes",
"}",
"matrix_items",
"=",
"[",
"]",
"for",
"i",
"in",
"self",
".",
"classes",
":",
"matrix_items",
".",
"append",
"(",
"(",
"i",
",",
"list",
"(",
"matrix_temp",
"[",
"i",
"]",
".",
"items",
"(",
")",
")",
")",
")",
"if",
"isinstance",
"(",
"actual_vector_temp",
",",
"numpy",
".",
"ndarray",
")",
":",
"actual_vector_temp",
"=",
"actual_vector_temp",
".",
"tolist",
"(",
")",
"if",
"isinstance",
"(",
"predict_vector_temp",
",",
"numpy",
".",
"ndarray",
")",
":",
"predict_vector_temp",
"=",
"predict_vector_temp",
".",
"tolist",
"(",
")",
"json",
".",
"dump",
"(",
"{",
"\"Actual-Vector\"",
":",
"actual_vector_temp",
",",
"\"Predict-Vector\"",
":",
"predict_vector_temp",
",",
"\"Matrix\"",
":",
"matrix_items",
",",
"\"Digit\"",
":",
"self",
".",
"digit",
",",
"\"Sample-Weight\"",
":",
"self",
".",
"weights",
",",
"\"Transpose\"",
":",
"self",
".",
"transpose",
"}",
",",
"obj_file",
")",
"if",
"address",
":",
"message",
"=",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"getcwd",
"(",
")",
",",
"name",
"+",
"\".obj\"",
")",
"return",
"{",
"\"Status\"",
":",
"True",
",",
"\"Message\"",
":",
"message",
"}",
"except",
"Exception",
"as",
"e",
":",
"return",
"{",
"\"Status\"",
":",
"False",
",",
"\"Message\"",
":",
"str",
"(",
"e",
")",
"}"
] |
Save ConfusionMatrix in .obj file.
:param name: filename
:type name : str
:param address: flag for address return
:type address : bool
:return: saving Status as dict {"Status":bool , "Message":str}
|
[
"Save",
"ConfusionMatrix",
"in",
".",
"obj",
"file",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_obj.py#L317-L350
|
236,270
|
sepandhaghighi/pycm
|
pycm/pycm_obj.py
|
ConfusionMatrix.F_beta
|
def F_beta(self, beta):
"""
Calculate FBeta score.
:param beta: beta parameter
:type beta : float
:return: FBeta score for classes as dict
"""
try:
F_dict = {}
for i in self.TP.keys():
F_dict[i] = F_calc(
TP=self.TP[i],
FP=self.FP[i],
FN=self.FN[i],
beta=beta)
return F_dict
except Exception:
return {}
|
python
|
def F_beta(self, beta):
"""
Calculate FBeta score.
:param beta: beta parameter
:type beta : float
:return: FBeta score for classes as dict
"""
try:
F_dict = {}
for i in self.TP.keys():
F_dict[i] = F_calc(
TP=self.TP[i],
FP=self.FP[i],
FN=self.FN[i],
beta=beta)
return F_dict
except Exception:
return {}
|
[
"def",
"F_beta",
"(",
"self",
",",
"beta",
")",
":",
"try",
":",
"F_dict",
"=",
"{",
"}",
"for",
"i",
"in",
"self",
".",
"TP",
".",
"keys",
"(",
")",
":",
"F_dict",
"[",
"i",
"]",
"=",
"F_calc",
"(",
"TP",
"=",
"self",
".",
"TP",
"[",
"i",
"]",
",",
"FP",
"=",
"self",
".",
"FP",
"[",
"i",
"]",
",",
"FN",
"=",
"self",
".",
"FN",
"[",
"i",
"]",
",",
"beta",
"=",
"beta",
")",
"return",
"F_dict",
"except",
"Exception",
":",
"return",
"{",
"}"
] |
Calculate FBeta score.
:param beta: beta parameter
:type beta : float
:return: FBeta score for classes as dict
|
[
"Calculate",
"FBeta",
"score",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_obj.py#L352-L370
|
236,271
|
sepandhaghighi/pycm
|
pycm/pycm_obj.py
|
ConfusionMatrix.IBA_alpha
|
def IBA_alpha(self, alpha):
"""
Calculate IBA_alpha score.
:param alpha: alpha parameter
:type alpha: float
:return: IBA_alpha score for classes as dict
"""
try:
IBA_dict = {}
for i in self.classes:
IBA_dict[i] = IBA_calc(self.TPR[i], self.TNR[i], alpha=alpha)
return IBA_dict
except Exception:
return {}
|
python
|
def IBA_alpha(self, alpha):
"""
Calculate IBA_alpha score.
:param alpha: alpha parameter
:type alpha: float
:return: IBA_alpha score for classes as dict
"""
try:
IBA_dict = {}
for i in self.classes:
IBA_dict[i] = IBA_calc(self.TPR[i], self.TNR[i], alpha=alpha)
return IBA_dict
except Exception:
return {}
|
[
"def",
"IBA_alpha",
"(",
"self",
",",
"alpha",
")",
":",
"try",
":",
"IBA_dict",
"=",
"{",
"}",
"for",
"i",
"in",
"self",
".",
"classes",
":",
"IBA_dict",
"[",
"i",
"]",
"=",
"IBA_calc",
"(",
"self",
".",
"TPR",
"[",
"i",
"]",
",",
"self",
".",
"TNR",
"[",
"i",
"]",
",",
"alpha",
"=",
"alpha",
")",
"return",
"IBA_dict",
"except",
"Exception",
":",
"return",
"{",
"}"
] |
Calculate IBA_alpha score.
:param alpha: alpha parameter
:type alpha: float
:return: IBA_alpha score for classes as dict
|
[
"Calculate",
"IBA_alpha",
"score",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_obj.py#L372-L386
|
236,272
|
sepandhaghighi/pycm
|
pycm/pycm_obj.py
|
ConfusionMatrix.relabel
|
def relabel(self, mapping):
"""
Rename ConfusionMatrix classes.
:param mapping: mapping dictionary
:type mapping : dict
:return: None
"""
if not isinstance(mapping, dict):
raise pycmMatrixError(MAPPING_FORMAT_ERROR)
if self.classes != list(mapping.keys()):
raise pycmMatrixError(MAPPING_CLASS_NAME_ERROR)
for row in self.classes:
temp_dict = {}
temp_dict_normalized = {}
for col in self.classes:
temp_dict[mapping[col]] = self.table[row][col]
temp_dict_normalized[mapping[col]
] = self.normalized_table[row][col]
del self.table[row]
self.table[mapping[row]] = temp_dict
del self.normalized_table[row]
self.normalized_table[mapping[row]] = temp_dict_normalized
self.matrix = self.table
self.normalized_matrix = self.normalized_table
for param in self.class_stat.keys():
temp_dict = {}
for classname in self.classes:
temp_dict[mapping[classname]
] = self.class_stat[param][classname]
self.class_stat[param] = temp_dict
self.classes = list(mapping.values())
self.TP = self.class_stat["TP"]
self.TN = self.class_stat["TN"]
self.FP = self.class_stat["FP"]
self.FN = self.class_stat["FN"]
__class_stat_init__(self)
|
python
|
def relabel(self, mapping):
"""
Rename ConfusionMatrix classes.
:param mapping: mapping dictionary
:type mapping : dict
:return: None
"""
if not isinstance(mapping, dict):
raise pycmMatrixError(MAPPING_FORMAT_ERROR)
if self.classes != list(mapping.keys()):
raise pycmMatrixError(MAPPING_CLASS_NAME_ERROR)
for row in self.classes:
temp_dict = {}
temp_dict_normalized = {}
for col in self.classes:
temp_dict[mapping[col]] = self.table[row][col]
temp_dict_normalized[mapping[col]
] = self.normalized_table[row][col]
del self.table[row]
self.table[mapping[row]] = temp_dict
del self.normalized_table[row]
self.normalized_table[mapping[row]] = temp_dict_normalized
self.matrix = self.table
self.normalized_matrix = self.normalized_table
for param in self.class_stat.keys():
temp_dict = {}
for classname in self.classes:
temp_dict[mapping[classname]
] = self.class_stat[param][classname]
self.class_stat[param] = temp_dict
self.classes = list(mapping.values())
self.TP = self.class_stat["TP"]
self.TN = self.class_stat["TN"]
self.FP = self.class_stat["FP"]
self.FN = self.class_stat["FN"]
__class_stat_init__(self)
|
[
"def",
"relabel",
"(",
"self",
",",
"mapping",
")",
":",
"if",
"not",
"isinstance",
"(",
"mapping",
",",
"dict",
")",
":",
"raise",
"pycmMatrixError",
"(",
"MAPPING_FORMAT_ERROR",
")",
"if",
"self",
".",
"classes",
"!=",
"list",
"(",
"mapping",
".",
"keys",
"(",
")",
")",
":",
"raise",
"pycmMatrixError",
"(",
"MAPPING_CLASS_NAME_ERROR",
")",
"for",
"row",
"in",
"self",
".",
"classes",
":",
"temp_dict",
"=",
"{",
"}",
"temp_dict_normalized",
"=",
"{",
"}",
"for",
"col",
"in",
"self",
".",
"classes",
":",
"temp_dict",
"[",
"mapping",
"[",
"col",
"]",
"]",
"=",
"self",
".",
"table",
"[",
"row",
"]",
"[",
"col",
"]",
"temp_dict_normalized",
"[",
"mapping",
"[",
"col",
"]",
"]",
"=",
"self",
".",
"normalized_table",
"[",
"row",
"]",
"[",
"col",
"]",
"del",
"self",
".",
"table",
"[",
"row",
"]",
"self",
".",
"table",
"[",
"mapping",
"[",
"row",
"]",
"]",
"=",
"temp_dict",
"del",
"self",
".",
"normalized_table",
"[",
"row",
"]",
"self",
".",
"normalized_table",
"[",
"mapping",
"[",
"row",
"]",
"]",
"=",
"temp_dict_normalized",
"self",
".",
"matrix",
"=",
"self",
".",
"table",
"self",
".",
"normalized_matrix",
"=",
"self",
".",
"normalized_table",
"for",
"param",
"in",
"self",
".",
"class_stat",
".",
"keys",
"(",
")",
":",
"temp_dict",
"=",
"{",
"}",
"for",
"classname",
"in",
"self",
".",
"classes",
":",
"temp_dict",
"[",
"mapping",
"[",
"classname",
"]",
"]",
"=",
"self",
".",
"class_stat",
"[",
"param",
"]",
"[",
"classname",
"]",
"self",
".",
"class_stat",
"[",
"param",
"]",
"=",
"temp_dict",
"self",
".",
"classes",
"=",
"list",
"(",
"mapping",
".",
"values",
"(",
")",
")",
"self",
".",
"TP",
"=",
"self",
".",
"class_stat",
"[",
"\"TP\"",
"]",
"self",
".",
"TN",
"=",
"self",
".",
"class_stat",
"[",
"\"TN\"",
"]",
"self",
".",
"FP",
"=",
"self",
".",
"class_stat",
"[",
"\"FP\"",
"]",
"self",
".",
"FN",
"=",
"self",
".",
"class_stat",
"[",
"\"FN\"",
"]",
"__class_stat_init__",
"(",
"self",
")"
] |
Rename ConfusionMatrix classes.
:param mapping: mapping dictionary
:type mapping : dict
:return: None
|
[
"Rename",
"ConfusionMatrix",
"classes",
"."
] |
cb03258afd6a821d10acba73c965aaac174bedcd
|
https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_obj.py#L426-L462
|
236,273
|
manns/pyspread
|
pyspread/src/gui/_toolbars.py
|
ToolbarBase.add_tools
|
def add_tools(self):
"""Adds tools from self.toolbardata to self"""
for data in self.toolbardata:
# tool type is in data[0]
if data[0] == "T":
# Simple tool
_, msg_type, label, tool_tip = data
icon = icons[label]
self.label2id[label] = tool_id = wx.NewId()
self.AddSimpleTool(tool_id, label, icon,
short_help_string=tool_tip)
self.ids_msgs[tool_id] = msg_type
self.parent.Bind(wx.EVT_TOOL, self.OnTool, id=tool_id)
elif data[0] == "S":
# Separator
self.AddSeparator()
elif data[0] == "C":
# Control
_, control, tool_tip = data
self.AddControl(control, label=tool_tip)
elif data[0] == "O":
# Check tool / option button
_, label, tool_tip = data
icon = icons[label]
self.label2id[label] = tool_id = wx.NewId()
self.AddCheckTool(tool_id, label, icon, icon, tool_tip)
else:
raise ValueError("Unknown tooltype " + str(data[0]))
self.SetCustomOverflowItems([], [])
self.Realize()
# Adjust Toolbar size
self.SetSize(self.DoGetBestSize())
|
python
|
def add_tools(self):
"""Adds tools from self.toolbardata to self"""
for data in self.toolbardata:
# tool type is in data[0]
if data[0] == "T":
# Simple tool
_, msg_type, label, tool_tip = data
icon = icons[label]
self.label2id[label] = tool_id = wx.NewId()
self.AddSimpleTool(tool_id, label, icon,
short_help_string=tool_tip)
self.ids_msgs[tool_id] = msg_type
self.parent.Bind(wx.EVT_TOOL, self.OnTool, id=tool_id)
elif data[0] == "S":
# Separator
self.AddSeparator()
elif data[0] == "C":
# Control
_, control, tool_tip = data
self.AddControl(control, label=tool_tip)
elif data[0] == "O":
# Check tool / option button
_, label, tool_tip = data
icon = icons[label]
self.label2id[label] = tool_id = wx.NewId()
self.AddCheckTool(tool_id, label, icon, icon, tool_tip)
else:
raise ValueError("Unknown tooltype " + str(data[0]))
self.SetCustomOverflowItems([], [])
self.Realize()
# Adjust Toolbar size
self.SetSize(self.DoGetBestSize())
|
[
"def",
"add_tools",
"(",
"self",
")",
":",
"for",
"data",
"in",
"self",
".",
"toolbardata",
":",
"# tool type is in data[0]",
"if",
"data",
"[",
"0",
"]",
"==",
"\"T\"",
":",
"# Simple tool",
"_",
",",
"msg_type",
",",
"label",
",",
"tool_tip",
"=",
"data",
"icon",
"=",
"icons",
"[",
"label",
"]",
"self",
".",
"label2id",
"[",
"label",
"]",
"=",
"tool_id",
"=",
"wx",
".",
"NewId",
"(",
")",
"self",
".",
"AddSimpleTool",
"(",
"tool_id",
",",
"label",
",",
"icon",
",",
"short_help_string",
"=",
"tool_tip",
")",
"self",
".",
"ids_msgs",
"[",
"tool_id",
"]",
"=",
"msg_type",
"self",
".",
"parent",
".",
"Bind",
"(",
"wx",
".",
"EVT_TOOL",
",",
"self",
".",
"OnTool",
",",
"id",
"=",
"tool_id",
")",
"elif",
"data",
"[",
"0",
"]",
"==",
"\"S\"",
":",
"# Separator",
"self",
".",
"AddSeparator",
"(",
")",
"elif",
"data",
"[",
"0",
"]",
"==",
"\"C\"",
":",
"# Control",
"_",
",",
"control",
",",
"tool_tip",
"=",
"data",
"self",
".",
"AddControl",
"(",
"control",
",",
"label",
"=",
"tool_tip",
")",
"elif",
"data",
"[",
"0",
"]",
"==",
"\"O\"",
":",
"# Check tool / option button",
"_",
",",
"label",
",",
"tool_tip",
"=",
"data",
"icon",
"=",
"icons",
"[",
"label",
"]",
"self",
".",
"label2id",
"[",
"label",
"]",
"=",
"tool_id",
"=",
"wx",
".",
"NewId",
"(",
")",
"self",
".",
"AddCheckTool",
"(",
"tool_id",
",",
"label",
",",
"icon",
",",
"icon",
",",
"tool_tip",
")",
"else",
":",
"raise",
"ValueError",
"(",
"\"Unknown tooltype \"",
"+",
"str",
"(",
"data",
"[",
"0",
"]",
")",
")",
"self",
".",
"SetCustomOverflowItems",
"(",
"[",
"]",
",",
"[",
"]",
")",
"self",
".",
"Realize",
"(",
")",
"# Adjust Toolbar size",
"self",
".",
"SetSize",
"(",
"self",
".",
"DoGetBestSize",
"(",
")",
")"
] |
Adds tools from self.toolbardata to self
|
[
"Adds",
"tools",
"from",
"self",
".",
"toolbardata",
"to",
"self"
] |
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
|
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_toolbars.py#L96-L146
|
236,274
|
manns/pyspread
|
pyspread/src/gui/_toolbars.py
|
ToolbarBase.OnTool
|
def OnTool(self, event):
"""Toolbar event handler"""
msgtype = self.ids_msgs[event.GetId()]
post_command_event(self, msgtype)
|
python
|
def OnTool(self, event):
"""Toolbar event handler"""
msgtype = self.ids_msgs[event.GetId()]
post_command_event(self, msgtype)
|
[
"def",
"OnTool",
"(",
"self",
",",
"event",
")",
":",
"msgtype",
"=",
"self",
".",
"ids_msgs",
"[",
"event",
".",
"GetId",
"(",
")",
"]",
"post_command_event",
"(",
"self",
",",
"msgtype",
")"
] |
Toolbar event handler
|
[
"Toolbar",
"event",
"handler"
] |
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
|
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_toolbars.py#L148-L152
|
236,275
|
manns/pyspread
|
pyspread/src/gui/_toolbars.py
|
MainToolbar.OnToggleTool
|
def OnToggleTool(self, event):
"""Tool event handler"""
config["check_spelling"] = str(event.IsChecked())
toggle_id = self.parent.menubar.FindMenuItem(_("View"),
_("Check spelling"))
if toggle_id != -1:
# Check may fail if translation is incomplete
toggle_item = self.parent.menubar.FindItemById(toggle_id)
toggle_item.Check(event.IsChecked())
self.parent.grid.grid_renderer.cell_cache.clear()
self.parent.grid.ForceRefresh()
event.Skip()
|
python
|
def OnToggleTool(self, event):
"""Tool event handler"""
config["check_spelling"] = str(event.IsChecked())
toggle_id = self.parent.menubar.FindMenuItem(_("View"),
_("Check spelling"))
if toggle_id != -1:
# Check may fail if translation is incomplete
toggle_item = self.parent.menubar.FindItemById(toggle_id)
toggle_item.Check(event.IsChecked())
self.parent.grid.grid_renderer.cell_cache.clear()
self.parent.grid.ForceRefresh()
event.Skip()
|
[
"def",
"OnToggleTool",
"(",
"self",
",",
"event",
")",
":",
"config",
"[",
"\"check_spelling\"",
"]",
"=",
"str",
"(",
"event",
".",
"IsChecked",
"(",
")",
")",
"toggle_id",
"=",
"self",
".",
"parent",
".",
"menubar",
".",
"FindMenuItem",
"(",
"_",
"(",
"\"View\"",
")",
",",
"_",
"(",
"\"Check spelling\"",
")",
")",
"if",
"toggle_id",
"!=",
"-",
"1",
":",
"# Check may fail if translation is incomplete",
"toggle_item",
"=",
"self",
".",
"parent",
".",
"menubar",
".",
"FindItemById",
"(",
"toggle_id",
")",
"toggle_item",
".",
"Check",
"(",
"event",
".",
"IsChecked",
"(",
")",
")",
"self",
".",
"parent",
".",
"grid",
".",
"grid_renderer",
".",
"cell_cache",
".",
"clear",
"(",
")",
"self",
".",
"parent",
".",
"grid",
".",
"ForceRefresh",
"(",
")",
"event",
".",
"Skip",
"(",
")"
] |
Tool event handler
|
[
"Tool",
"event",
"handler"
] |
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
|
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_toolbars.py#L209-L223
|
236,276
|
manns/pyspread
|
pyspread/src/gui/_toolbars.py
|
WidgetToolbar._get_button_label
|
def _get_button_label(self):
"""Gets Button label from user and returns string"""
dlg = wx.TextEntryDialog(self, _('Button label:'))
if dlg.ShowModal() == wx.ID_OK:
label = dlg.GetValue()
else:
label = ""
dlg.Destroy()
return label
|
python
|
def _get_button_label(self):
"""Gets Button label from user and returns string"""
dlg = wx.TextEntryDialog(self, _('Button label:'))
if dlg.ShowModal() == wx.ID_OK:
label = dlg.GetValue()
else:
label = ""
dlg.Destroy()
return label
|
[
"def",
"_get_button_label",
"(",
"self",
")",
":",
"dlg",
"=",
"wx",
".",
"TextEntryDialog",
"(",
"self",
",",
"_",
"(",
"'Button label:'",
")",
")",
"if",
"dlg",
".",
"ShowModal",
"(",
")",
"==",
"wx",
".",
"ID_OK",
":",
"label",
"=",
"dlg",
".",
"GetValue",
"(",
")",
"else",
":",
"label",
"=",
"\"\"",
"dlg",
".",
"Destroy",
"(",
")",
"return",
"label"
] |
Gets Button label from user and returns string
|
[
"Gets",
"Button",
"label",
"from",
"user",
"and",
"returns",
"string"
] |
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
|
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_toolbars.py#L303-L315
|
236,277
|
manns/pyspread
|
pyspread/src/gui/_toolbars.py
|
WidgetToolbar.OnButtonCell
|
def OnButtonCell(self, event):
"""Event handler for cell button toggle button"""
if self.button_cell_button_id == event.GetId():
if event.IsChecked():
label = self._get_button_label()
post_command_event(self, self.ButtonCellMsg, text=label)
else:
post_command_event(self, self.ButtonCellMsg, text=False)
event.Skip()
|
python
|
def OnButtonCell(self, event):
"""Event handler for cell button toggle button"""
if self.button_cell_button_id == event.GetId():
if event.IsChecked():
label = self._get_button_label()
post_command_event(self, self.ButtonCellMsg, text=label)
else:
post_command_event(self, self.ButtonCellMsg, text=False)
event.Skip()
|
[
"def",
"OnButtonCell",
"(",
"self",
",",
"event",
")",
":",
"if",
"self",
".",
"button_cell_button_id",
"==",
"event",
".",
"GetId",
"(",
")",
":",
"if",
"event",
".",
"IsChecked",
"(",
")",
":",
"label",
"=",
"self",
".",
"_get_button_label",
"(",
")",
"post_command_event",
"(",
"self",
",",
"self",
".",
"ButtonCellMsg",
",",
"text",
"=",
"label",
")",
"else",
":",
"post_command_event",
"(",
"self",
",",
"self",
".",
"ButtonCellMsg",
",",
"text",
"=",
"False",
")",
"event",
".",
"Skip",
"(",
")"
] |
Event handler for cell button toggle button
|
[
"Event",
"handler",
"for",
"cell",
"button",
"toggle",
"button"
] |
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
|
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_toolbars.py#L317-L327
|
236,278
|
manns/pyspread
|
pyspread/src/gui/_toolbars.py
|
WidgetToolbar.OnVideoCell
|
def OnVideoCell(self, event):
"""Event handler for video cell toggle button"""
if self.video_cell_button_id == event.GetId():
if event.IsChecked():
wildcard = _("Media files") + " (*.*)|*.*"
videofile, __ = self.get_filepath_findex_from_user(
wildcard, "Choose video or audio file", wx.OPEN)
post_command_event(self, self.VideoCellMsg,
videofile=videofile)
else:
post_command_event(self, self.VideoCellMsg, videofile=False)
event.Skip()
|
python
|
def OnVideoCell(self, event):
"""Event handler for video cell toggle button"""
if self.video_cell_button_id == event.GetId():
if event.IsChecked():
wildcard = _("Media files") + " (*.*)|*.*"
videofile, __ = self.get_filepath_findex_from_user(
wildcard, "Choose video or audio file", wx.OPEN)
post_command_event(self, self.VideoCellMsg,
videofile=videofile)
else:
post_command_event(self, self.VideoCellMsg, videofile=False)
event.Skip()
|
[
"def",
"OnVideoCell",
"(",
"self",
",",
"event",
")",
":",
"if",
"self",
".",
"video_cell_button_id",
"==",
"event",
".",
"GetId",
"(",
")",
":",
"if",
"event",
".",
"IsChecked",
"(",
")",
":",
"wildcard",
"=",
"_",
"(",
"\"Media files\"",
")",
"+",
"\" (*.*)|*.*\"",
"videofile",
",",
"__",
"=",
"self",
".",
"get_filepath_findex_from_user",
"(",
"wildcard",
",",
"\"Choose video or audio file\"",
",",
"wx",
".",
"OPEN",
")",
"post_command_event",
"(",
"self",
",",
"self",
".",
"VideoCellMsg",
",",
"videofile",
"=",
"videofile",
")",
"else",
":",
"post_command_event",
"(",
"self",
",",
"self",
".",
"VideoCellMsg",
",",
"videofile",
"=",
"False",
")",
"event",
".",
"Skip",
"(",
")"
] |
Event handler for video cell toggle button
|
[
"Event",
"handler",
"for",
"video",
"cell",
"toggle",
"button"
] |
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
|
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_toolbars.py#L329-L342
|
236,279
|
manns/pyspread
|
pyspread/src/gui/_toolbars.py
|
FindToolbar.make_menu
|
def make_menu(self):
"""Creates the search menu"""
menu = wx.Menu()
item = menu.Append(-1, "Recent Searches")
item.Enable(False)
for __id, txt in enumerate(self.search_history):
menu.Append(__id, txt)
return menu
|
python
|
def make_menu(self):
"""Creates the search menu"""
menu = wx.Menu()
item = menu.Append(-1, "Recent Searches")
item.Enable(False)
for __id, txt in enumerate(self.search_history):
menu.Append(__id, txt)
return menu
|
[
"def",
"make_menu",
"(",
"self",
")",
":",
"menu",
"=",
"wx",
".",
"Menu",
"(",
")",
"item",
"=",
"menu",
".",
"Append",
"(",
"-",
"1",
",",
"\"Recent Searches\"",
")",
"item",
".",
"Enable",
"(",
"False",
")",
"for",
"__id",
",",
"txt",
"in",
"enumerate",
"(",
"self",
".",
"search_history",
")",
":",
"menu",
".",
"Append",
"(",
"__id",
",",
"txt",
")",
"return",
"menu"
] |
Creates the search menu
|
[
"Creates",
"the",
"search",
"menu"
] |
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
|
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_toolbars.py#L427-L436
|
236,280
|
manns/pyspread
|
pyspread/src/gui/_toolbars.py
|
FindToolbar.OnMenu
|
def OnMenu(self, event):
"""Search history has been selected"""
__id = event.GetId()
try:
menuitem = event.GetEventObject().FindItemById(__id)
selected_text = menuitem.GetItemLabel()
self.search.SetValue(selected_text)
except AttributeError:
# Not called by menu
event.Skip()
|
python
|
def OnMenu(self, event):
"""Search history has been selected"""
__id = event.GetId()
try:
menuitem = event.GetEventObject().FindItemById(__id)
selected_text = menuitem.GetItemLabel()
self.search.SetValue(selected_text)
except AttributeError:
# Not called by menu
event.Skip()
|
[
"def",
"OnMenu",
"(",
"self",
",",
"event",
")",
":",
"__id",
"=",
"event",
".",
"GetId",
"(",
")",
"try",
":",
"menuitem",
"=",
"event",
".",
"GetEventObject",
"(",
")",
".",
"FindItemById",
"(",
"__id",
")",
"selected_text",
"=",
"menuitem",
".",
"GetItemLabel",
"(",
")",
"self",
".",
"search",
".",
"SetValue",
"(",
"selected_text",
")",
"except",
"AttributeError",
":",
"# Not called by menu",
"event",
".",
"Skip",
"(",
")"
] |
Search history has been selected
|
[
"Search",
"history",
"has",
"been",
"selected"
] |
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
|
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_toolbars.py#L438-L448
|
236,281
|
manns/pyspread
|
pyspread/src/gui/_toolbars.py
|
FindToolbar.OnSearch
|
def OnSearch(self, event):
"""Event handler for starting the search"""
search_string = self.search.GetValue()
if search_string not in self.search_history:
self.search_history.append(search_string)
if len(self.search_history) > 10:
self.search_history.pop(0)
self.menu = self.make_menu()
self.search.SetMenu(self.menu)
search_flags = self.search_options + ["FIND_NEXT"]
post_command_event(self, self.FindMsg, text=search_string,
flags=search_flags)
self.search.SetFocus()
|
python
|
def OnSearch(self, event):
"""Event handler for starting the search"""
search_string = self.search.GetValue()
if search_string not in self.search_history:
self.search_history.append(search_string)
if len(self.search_history) > 10:
self.search_history.pop(0)
self.menu = self.make_menu()
self.search.SetMenu(self.menu)
search_flags = self.search_options + ["FIND_NEXT"]
post_command_event(self, self.FindMsg, text=search_string,
flags=search_flags)
self.search.SetFocus()
|
[
"def",
"OnSearch",
"(",
"self",
",",
"event",
")",
":",
"search_string",
"=",
"self",
".",
"search",
".",
"GetValue",
"(",
")",
"if",
"search_string",
"not",
"in",
"self",
".",
"search_history",
":",
"self",
".",
"search_history",
".",
"append",
"(",
"search_string",
")",
"if",
"len",
"(",
"self",
".",
"search_history",
")",
">",
"10",
":",
"self",
".",
"search_history",
".",
"pop",
"(",
"0",
")",
"self",
".",
"menu",
"=",
"self",
".",
"make_menu",
"(",
")",
"self",
".",
"search",
".",
"SetMenu",
"(",
"self",
".",
"menu",
")",
"search_flags",
"=",
"self",
".",
"search_options",
"+",
"[",
"\"FIND_NEXT\"",
"]",
"post_command_event",
"(",
"self",
",",
"self",
".",
"FindMsg",
",",
"text",
"=",
"search_string",
",",
"flags",
"=",
"search_flags",
")",
"self",
".",
"search",
".",
"SetFocus",
"(",
")"
] |
Event handler for starting the search
|
[
"Event",
"handler",
"for",
"starting",
"the",
"search"
] |
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
|
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_toolbars.py#L450-L468
|
236,282
|
manns/pyspread
|
pyspread/src/gui/_toolbars.py
|
FindToolbar.OnSearchDirectionButton
|
def OnSearchDirectionButton(self, event):
"""Event handler for search direction toggle button"""
if "DOWN" in self.search_options:
flag_index = self.search_options.index("DOWN")
self.search_options[flag_index] = "UP"
elif "UP" in self.search_options:
flag_index = self.search_options.index("UP")
self.search_options[flag_index] = "DOWN"
else:
raise AttributeError(_("Neither UP nor DOWN in search_flags"))
event.Skip()
|
python
|
def OnSearchDirectionButton(self, event):
"""Event handler for search direction toggle button"""
if "DOWN" in self.search_options:
flag_index = self.search_options.index("DOWN")
self.search_options[flag_index] = "UP"
elif "UP" in self.search_options:
flag_index = self.search_options.index("UP")
self.search_options[flag_index] = "DOWN"
else:
raise AttributeError(_("Neither UP nor DOWN in search_flags"))
event.Skip()
|
[
"def",
"OnSearchDirectionButton",
"(",
"self",
",",
"event",
")",
":",
"if",
"\"DOWN\"",
"in",
"self",
".",
"search_options",
":",
"flag_index",
"=",
"self",
".",
"search_options",
".",
"index",
"(",
"\"DOWN\"",
")",
"self",
".",
"search_options",
"[",
"flag_index",
"]",
"=",
"\"UP\"",
"elif",
"\"UP\"",
"in",
"self",
".",
"search_options",
":",
"flag_index",
"=",
"self",
".",
"search_options",
".",
"index",
"(",
"\"UP\"",
")",
"self",
".",
"search_options",
"[",
"flag_index",
"]",
"=",
"\"DOWN\"",
"else",
":",
"raise",
"AttributeError",
"(",
"_",
"(",
"\"Neither UP nor DOWN in search_flags\"",
")",
")",
"event",
".",
"Skip",
"(",
")"
] |
Event handler for search direction toggle button
|
[
"Event",
"handler",
"for",
"search",
"direction",
"toggle",
"button"
] |
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
|
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_toolbars.py#L470-L482
|
236,283
|
manns/pyspread
|
pyspread/src/gui/_toolbars.py
|
FindToolbar.OnSearchFlag
|
def OnSearchFlag(self, event):
"""Event handler for search flag toggle buttons"""
for label in self.search_options_buttons:
button_id = self.label2id[label]
if button_id == event.GetId():
if event.IsChecked():
self.search_options.append(label)
else:
flag_index = self.search_options.index(label)
self.search_options.pop(flag_index)
event.Skip()
|
python
|
def OnSearchFlag(self, event):
"""Event handler for search flag toggle buttons"""
for label in self.search_options_buttons:
button_id = self.label2id[label]
if button_id == event.GetId():
if event.IsChecked():
self.search_options.append(label)
else:
flag_index = self.search_options.index(label)
self.search_options.pop(flag_index)
event.Skip()
|
[
"def",
"OnSearchFlag",
"(",
"self",
",",
"event",
")",
":",
"for",
"label",
"in",
"self",
".",
"search_options_buttons",
":",
"button_id",
"=",
"self",
".",
"label2id",
"[",
"label",
"]",
"if",
"button_id",
"==",
"event",
".",
"GetId",
"(",
")",
":",
"if",
"event",
".",
"IsChecked",
"(",
")",
":",
"self",
".",
"search_options",
".",
"append",
"(",
"label",
")",
"else",
":",
"flag_index",
"=",
"self",
".",
"search_options",
".",
"index",
"(",
"label",
")",
"self",
".",
"search_options",
".",
"pop",
"(",
"flag_index",
")",
"event",
".",
"Skip",
"(",
")"
] |
Event handler for search flag toggle buttons
|
[
"Event",
"handler",
"for",
"search",
"flag",
"toggle",
"buttons"
] |
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
|
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_toolbars.py#L484-L496
|
236,284
|
manns/pyspread
|
pyspread/src/gui/_toolbars.py
|
AttributesToolbar._create_font_choice_combo
|
def _create_font_choice_combo(self):
"""Creates font choice combo box"""
self.fonts = get_font_list()
self.font_choice_combo = \
_widgets.FontChoiceCombobox(self, choices=self.fonts,
style=wx.CB_READONLY, size=(125, -1))
self.font_choice_combo.SetToolTipString(_(u"Text font"))
self.AddControl(self.font_choice_combo)
self.Bind(wx.EVT_COMBOBOX, self.OnTextFont, self.font_choice_combo)
self.parent.Bind(self.EVT_CMD_TOOLBAR_UPDATE, self.OnUpdate)
|
python
|
def _create_font_choice_combo(self):
"""Creates font choice combo box"""
self.fonts = get_font_list()
self.font_choice_combo = \
_widgets.FontChoiceCombobox(self, choices=self.fonts,
style=wx.CB_READONLY, size=(125, -1))
self.font_choice_combo.SetToolTipString(_(u"Text font"))
self.AddControl(self.font_choice_combo)
self.Bind(wx.EVT_COMBOBOX, self.OnTextFont, self.font_choice_combo)
self.parent.Bind(self.EVT_CMD_TOOLBAR_UPDATE, self.OnUpdate)
|
[
"def",
"_create_font_choice_combo",
"(",
"self",
")",
":",
"self",
".",
"fonts",
"=",
"get_font_list",
"(",
")",
"self",
".",
"font_choice_combo",
"=",
"_widgets",
".",
"FontChoiceCombobox",
"(",
"self",
",",
"choices",
"=",
"self",
".",
"fonts",
",",
"style",
"=",
"wx",
".",
"CB_READONLY",
",",
"size",
"=",
"(",
"125",
",",
"-",
"1",
")",
")",
"self",
".",
"font_choice_combo",
".",
"SetToolTipString",
"(",
"_",
"(",
"u\"Text font\"",
")",
")",
"self",
".",
"AddControl",
"(",
"self",
".",
"font_choice_combo",
")",
"self",
".",
"Bind",
"(",
"wx",
".",
"EVT_COMBOBOX",
",",
"self",
".",
"OnTextFont",
",",
"self",
".",
"font_choice_combo",
")",
"self",
".",
"parent",
".",
"Bind",
"(",
"self",
".",
"EVT_CMD_TOOLBAR_UPDATE",
",",
"self",
".",
"OnUpdate",
")"
] |
Creates font choice combo box
|
[
"Creates",
"font",
"choice",
"combo",
"box"
] |
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
|
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_toolbars.py#L561-L574
|
236,285
|
manns/pyspread
|
pyspread/src/gui/_toolbars.py
|
AttributesToolbar._create_font_size_combo
|
def _create_font_size_combo(self):
"""Creates font size combo box"""
self.std_font_sizes = config["font_default_sizes"]
font_size = str(get_default_font().GetPointSize())
self.font_size_combo = \
wx.ComboBox(self, -1, value=font_size, size=(60, -1),
choices=map(unicode, self.std_font_sizes),
style=wx.CB_DROPDOWN | wx.TE_PROCESS_ENTER)
self.font_size_combo.SetToolTipString(_(u"Text size\n(points)"))
self.AddControl(self.font_size_combo)
self.Bind(wx.EVT_COMBOBOX, self.OnTextSize, self.font_size_combo)
self.Bind(wx.EVT_TEXT_ENTER, self.OnTextSize, self.font_size_combo)
|
python
|
def _create_font_size_combo(self):
"""Creates font size combo box"""
self.std_font_sizes = config["font_default_sizes"]
font_size = str(get_default_font().GetPointSize())
self.font_size_combo = \
wx.ComboBox(self, -1, value=font_size, size=(60, -1),
choices=map(unicode, self.std_font_sizes),
style=wx.CB_DROPDOWN | wx.TE_PROCESS_ENTER)
self.font_size_combo.SetToolTipString(_(u"Text size\n(points)"))
self.AddControl(self.font_size_combo)
self.Bind(wx.EVT_COMBOBOX, self.OnTextSize, self.font_size_combo)
self.Bind(wx.EVT_TEXT_ENTER, self.OnTextSize, self.font_size_combo)
|
[
"def",
"_create_font_size_combo",
"(",
"self",
")",
":",
"self",
".",
"std_font_sizes",
"=",
"config",
"[",
"\"font_default_sizes\"",
"]",
"font_size",
"=",
"str",
"(",
"get_default_font",
"(",
")",
".",
"GetPointSize",
"(",
")",
")",
"self",
".",
"font_size_combo",
"=",
"wx",
".",
"ComboBox",
"(",
"self",
",",
"-",
"1",
",",
"value",
"=",
"font_size",
",",
"size",
"=",
"(",
"60",
",",
"-",
"1",
")",
",",
"choices",
"=",
"map",
"(",
"unicode",
",",
"self",
".",
"std_font_sizes",
")",
",",
"style",
"=",
"wx",
".",
"CB_DROPDOWN",
"|",
"wx",
".",
"TE_PROCESS_ENTER",
")",
"self",
".",
"font_size_combo",
".",
"SetToolTipString",
"(",
"_",
"(",
"u\"Text size\\n(points)\"",
")",
")",
"self",
".",
"AddControl",
"(",
"self",
".",
"font_size_combo",
")",
"self",
".",
"Bind",
"(",
"wx",
".",
"EVT_COMBOBOX",
",",
"self",
".",
"OnTextSize",
",",
"self",
".",
"font_size_combo",
")",
"self",
".",
"Bind",
"(",
"wx",
".",
"EVT_TEXT_ENTER",
",",
"self",
".",
"OnTextSize",
",",
"self",
".",
"font_size_combo",
")"
] |
Creates font size combo box
|
[
"Creates",
"font",
"size",
"combo",
"box"
] |
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
|
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_toolbars.py#L576-L590
|
236,286
|
manns/pyspread
|
pyspread/src/gui/_toolbars.py
|
AttributesToolbar._create_font_face_buttons
|
def _create_font_face_buttons(self):
"""Creates font face buttons"""
font_face_buttons = [
(wx.FONTFLAG_BOLD, "OnBold", "FormatTextBold", _("Bold")),
(wx.FONTFLAG_ITALIC, "OnItalics", "FormatTextItalic",
_("Italics")),
(wx.FONTFLAG_UNDERLINED, "OnUnderline", "FormatTextUnderline",
_("Underline")),
(wx.FONTFLAG_STRIKETHROUGH, "OnStrikethrough",
"FormatTextStrikethrough", _("Strikethrough")),
(wx.FONTFLAG_MASK, "OnFreeze", "Freeze", _("Freeze")),
(wx.FONTFLAG_NOT_ANTIALIASED, "OnLock", "Lock", _("Lock cell")),
(wx.FONTFAMILY_DECORATIVE, "OnMarkup", "Markup", _("Markup")),
]
for __id, method, iconname, helpstring in font_face_buttons:
bmp = icons[iconname]
self.AddCheckTool(__id, iconname, bmp, bmp,
short_help_string=helpstring)
self.Bind(wx.EVT_TOOL, getattr(self, method), id=__id)
|
python
|
def _create_font_face_buttons(self):
"""Creates font face buttons"""
font_face_buttons = [
(wx.FONTFLAG_BOLD, "OnBold", "FormatTextBold", _("Bold")),
(wx.FONTFLAG_ITALIC, "OnItalics", "FormatTextItalic",
_("Italics")),
(wx.FONTFLAG_UNDERLINED, "OnUnderline", "FormatTextUnderline",
_("Underline")),
(wx.FONTFLAG_STRIKETHROUGH, "OnStrikethrough",
"FormatTextStrikethrough", _("Strikethrough")),
(wx.FONTFLAG_MASK, "OnFreeze", "Freeze", _("Freeze")),
(wx.FONTFLAG_NOT_ANTIALIASED, "OnLock", "Lock", _("Lock cell")),
(wx.FONTFAMILY_DECORATIVE, "OnMarkup", "Markup", _("Markup")),
]
for __id, method, iconname, helpstring in font_face_buttons:
bmp = icons[iconname]
self.AddCheckTool(__id, iconname, bmp, bmp,
short_help_string=helpstring)
self.Bind(wx.EVT_TOOL, getattr(self, method), id=__id)
|
[
"def",
"_create_font_face_buttons",
"(",
"self",
")",
":",
"font_face_buttons",
"=",
"[",
"(",
"wx",
".",
"FONTFLAG_BOLD",
",",
"\"OnBold\"",
",",
"\"FormatTextBold\"",
",",
"_",
"(",
"\"Bold\"",
")",
")",
",",
"(",
"wx",
".",
"FONTFLAG_ITALIC",
",",
"\"OnItalics\"",
",",
"\"FormatTextItalic\"",
",",
"_",
"(",
"\"Italics\"",
")",
")",
",",
"(",
"wx",
".",
"FONTFLAG_UNDERLINED",
",",
"\"OnUnderline\"",
",",
"\"FormatTextUnderline\"",
",",
"_",
"(",
"\"Underline\"",
")",
")",
",",
"(",
"wx",
".",
"FONTFLAG_STRIKETHROUGH",
",",
"\"OnStrikethrough\"",
",",
"\"FormatTextStrikethrough\"",
",",
"_",
"(",
"\"Strikethrough\"",
")",
")",
",",
"(",
"wx",
".",
"FONTFLAG_MASK",
",",
"\"OnFreeze\"",
",",
"\"Freeze\"",
",",
"_",
"(",
"\"Freeze\"",
")",
")",
",",
"(",
"wx",
".",
"FONTFLAG_NOT_ANTIALIASED",
",",
"\"OnLock\"",
",",
"\"Lock\"",
",",
"_",
"(",
"\"Lock cell\"",
")",
")",
",",
"(",
"wx",
".",
"FONTFAMILY_DECORATIVE",
",",
"\"OnMarkup\"",
",",
"\"Markup\"",
",",
"_",
"(",
"\"Markup\"",
")",
")",
",",
"]",
"for",
"__id",
",",
"method",
",",
"iconname",
",",
"helpstring",
"in",
"font_face_buttons",
":",
"bmp",
"=",
"icons",
"[",
"iconname",
"]",
"self",
".",
"AddCheckTool",
"(",
"__id",
",",
"iconname",
",",
"bmp",
",",
"bmp",
",",
"short_help_string",
"=",
"helpstring",
")",
"self",
".",
"Bind",
"(",
"wx",
".",
"EVT_TOOL",
",",
"getattr",
"(",
"self",
",",
"method",
")",
",",
"id",
"=",
"__id",
")"
] |
Creates font face buttons
|
[
"Creates",
"font",
"face",
"buttons"
] |
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
|
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_toolbars.py#L592-L612
|
236,287
|
manns/pyspread
|
pyspread/src/gui/_toolbars.py
|
AttributesToolbar._create_textrotation_button
|
def _create_textrotation_button(self):
"""Create text rotation toggle button"""
iconnames = ["TextRotate270", "TextRotate0", "TextRotate90",
"TextRotate180"]
bmplist = [icons[iconname] for iconname in iconnames]
self.rotation_tb = _widgets.BitmapToggleButton(self, bmplist)
self.rotation_tb.SetToolTipString(_(u"Cell text rotation"))
self.Bind(wx.EVT_BUTTON, self.OnRotate, self.rotation_tb)
self.AddControl(self.rotation_tb)
|
python
|
def _create_textrotation_button(self):
"""Create text rotation toggle button"""
iconnames = ["TextRotate270", "TextRotate0", "TextRotate90",
"TextRotate180"]
bmplist = [icons[iconname] for iconname in iconnames]
self.rotation_tb = _widgets.BitmapToggleButton(self, bmplist)
self.rotation_tb.SetToolTipString(_(u"Cell text rotation"))
self.Bind(wx.EVT_BUTTON, self.OnRotate, self.rotation_tb)
self.AddControl(self.rotation_tb)
|
[
"def",
"_create_textrotation_button",
"(",
"self",
")",
":",
"iconnames",
"=",
"[",
"\"TextRotate270\"",
",",
"\"TextRotate0\"",
",",
"\"TextRotate90\"",
",",
"\"TextRotate180\"",
"]",
"bmplist",
"=",
"[",
"icons",
"[",
"iconname",
"]",
"for",
"iconname",
"in",
"iconnames",
"]",
"self",
".",
"rotation_tb",
"=",
"_widgets",
".",
"BitmapToggleButton",
"(",
"self",
",",
"bmplist",
")",
"self",
".",
"rotation_tb",
".",
"SetToolTipString",
"(",
"_",
"(",
"u\"Cell text rotation\"",
")",
")",
"self",
".",
"Bind",
"(",
"wx",
".",
"EVT_BUTTON",
",",
"self",
".",
"OnRotate",
",",
"self",
".",
"rotation_tb",
")",
"self",
".",
"AddControl",
"(",
"self",
".",
"rotation_tb",
")"
] |
Create text rotation toggle button
|
[
"Create",
"text",
"rotation",
"toggle",
"button"
] |
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
|
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_toolbars.py#L614-L624
|
236,288
|
manns/pyspread
|
pyspread/src/gui/_toolbars.py
|
AttributesToolbar._create_justification_button
|
def _create_justification_button(self):
"""Creates horizontal justification button"""
iconnames = ["JustifyLeft", "JustifyCenter", "JustifyRight"]
bmplist = [icons[iconname] for iconname in iconnames]
self.justify_tb = _widgets.BitmapToggleButton(self, bmplist)
self.justify_tb.SetToolTipString(_(u"Justification"))
self.Bind(wx.EVT_BUTTON, self.OnJustification, self.justify_tb)
self.AddControl(self.justify_tb)
|
python
|
def _create_justification_button(self):
"""Creates horizontal justification button"""
iconnames = ["JustifyLeft", "JustifyCenter", "JustifyRight"]
bmplist = [icons[iconname] for iconname in iconnames]
self.justify_tb = _widgets.BitmapToggleButton(self, bmplist)
self.justify_tb.SetToolTipString(_(u"Justification"))
self.Bind(wx.EVT_BUTTON, self.OnJustification, self.justify_tb)
self.AddControl(self.justify_tb)
|
[
"def",
"_create_justification_button",
"(",
"self",
")",
":",
"iconnames",
"=",
"[",
"\"JustifyLeft\"",
",",
"\"JustifyCenter\"",
",",
"\"JustifyRight\"",
"]",
"bmplist",
"=",
"[",
"icons",
"[",
"iconname",
"]",
"for",
"iconname",
"in",
"iconnames",
"]",
"self",
".",
"justify_tb",
"=",
"_widgets",
".",
"BitmapToggleButton",
"(",
"self",
",",
"bmplist",
")",
"self",
".",
"justify_tb",
".",
"SetToolTipString",
"(",
"_",
"(",
"u\"Justification\"",
")",
")",
"self",
".",
"Bind",
"(",
"wx",
".",
"EVT_BUTTON",
",",
"self",
".",
"OnJustification",
",",
"self",
".",
"justify_tb",
")",
"self",
".",
"AddControl",
"(",
"self",
".",
"justify_tb",
")"
] |
Creates horizontal justification button
|
[
"Creates",
"horizontal",
"justification",
"button"
] |
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
|
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_toolbars.py#L626-L634
|
236,289
|
manns/pyspread
|
pyspread/src/gui/_toolbars.py
|
AttributesToolbar._create_alignment_button
|
def _create_alignment_button(self):
"""Creates vertical alignment button"""
iconnames = ["AlignTop", "AlignCenter", "AlignBottom"]
bmplist = [icons[iconname] for iconname in iconnames]
self.alignment_tb = _widgets.BitmapToggleButton(self, bmplist)
self.alignment_tb.SetToolTipString(_(u"Alignment"))
self.Bind(wx.EVT_BUTTON, self.OnAlignment, self.alignment_tb)
self.AddControl(self.alignment_tb)
|
python
|
def _create_alignment_button(self):
"""Creates vertical alignment button"""
iconnames = ["AlignTop", "AlignCenter", "AlignBottom"]
bmplist = [icons[iconname] for iconname in iconnames]
self.alignment_tb = _widgets.BitmapToggleButton(self, bmplist)
self.alignment_tb.SetToolTipString(_(u"Alignment"))
self.Bind(wx.EVT_BUTTON, self.OnAlignment, self.alignment_tb)
self.AddControl(self.alignment_tb)
|
[
"def",
"_create_alignment_button",
"(",
"self",
")",
":",
"iconnames",
"=",
"[",
"\"AlignTop\"",
",",
"\"AlignCenter\"",
",",
"\"AlignBottom\"",
"]",
"bmplist",
"=",
"[",
"icons",
"[",
"iconname",
"]",
"for",
"iconname",
"in",
"iconnames",
"]",
"self",
".",
"alignment_tb",
"=",
"_widgets",
".",
"BitmapToggleButton",
"(",
"self",
",",
"bmplist",
")",
"self",
".",
"alignment_tb",
".",
"SetToolTipString",
"(",
"_",
"(",
"u\"Alignment\"",
")",
")",
"self",
".",
"Bind",
"(",
"wx",
".",
"EVT_BUTTON",
",",
"self",
".",
"OnAlignment",
",",
"self",
".",
"alignment_tb",
")",
"self",
".",
"AddControl",
"(",
"self",
".",
"alignment_tb",
")"
] |
Creates vertical alignment button
|
[
"Creates",
"vertical",
"alignment",
"button"
] |
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
|
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_toolbars.py#L636-L645
|
236,290
|
manns/pyspread
|
pyspread/src/gui/_toolbars.py
|
AttributesToolbar._create_borderchoice_combo
|
def _create_borderchoice_combo(self):
"""Create border choice combo box"""
choices = [c[0] for c in self.border_toggles]
self.borderchoice_combo = \
_widgets.BorderEditChoice(self, choices=choices,
style=wx.CB_READONLY, size=(50, -1))
self.borderchoice_combo.SetToolTipString(
_(u"Choose borders for which attributes are changed"))
self.borderstate = self.border_toggles[0][0]
self.AddControl(self.borderchoice_combo)
self.Bind(wx.EVT_COMBOBOX, self.OnBorderChoice,
self.borderchoice_combo)
self.borderchoice_combo.SetValue("AllBorders")
|
python
|
def _create_borderchoice_combo(self):
"""Create border choice combo box"""
choices = [c[0] for c in self.border_toggles]
self.borderchoice_combo = \
_widgets.BorderEditChoice(self, choices=choices,
style=wx.CB_READONLY, size=(50, -1))
self.borderchoice_combo.SetToolTipString(
_(u"Choose borders for which attributes are changed"))
self.borderstate = self.border_toggles[0][0]
self.AddControl(self.borderchoice_combo)
self.Bind(wx.EVT_COMBOBOX, self.OnBorderChoice,
self.borderchoice_combo)
self.borderchoice_combo.SetValue("AllBorders")
|
[
"def",
"_create_borderchoice_combo",
"(",
"self",
")",
":",
"choices",
"=",
"[",
"c",
"[",
"0",
"]",
"for",
"c",
"in",
"self",
".",
"border_toggles",
"]",
"self",
".",
"borderchoice_combo",
"=",
"_widgets",
".",
"BorderEditChoice",
"(",
"self",
",",
"choices",
"=",
"choices",
",",
"style",
"=",
"wx",
".",
"CB_READONLY",
",",
"size",
"=",
"(",
"50",
",",
"-",
"1",
")",
")",
"self",
".",
"borderchoice_combo",
".",
"SetToolTipString",
"(",
"_",
"(",
"u\"Choose borders for which attributes are changed\"",
")",
")",
"self",
".",
"borderstate",
"=",
"self",
".",
"border_toggles",
"[",
"0",
"]",
"[",
"0",
"]",
"self",
".",
"AddControl",
"(",
"self",
".",
"borderchoice_combo",
")",
"self",
".",
"Bind",
"(",
"wx",
".",
"EVT_COMBOBOX",
",",
"self",
".",
"OnBorderChoice",
",",
"self",
".",
"borderchoice_combo",
")",
"self",
".",
"borderchoice_combo",
".",
"SetValue",
"(",
"\"AllBorders\"",
")"
] |
Create border choice combo box
|
[
"Create",
"border",
"choice",
"combo",
"box"
] |
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
|
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_toolbars.py#L647-L665
|
236,291
|
manns/pyspread
|
pyspread/src/gui/_toolbars.py
|
AttributesToolbar._create_penwidth_combo
|
def _create_penwidth_combo(self):
"""Create pen width combo box"""
choices = map(unicode, xrange(12))
self.pen_width_combo = \
_widgets.PenWidthComboBox(self, choices=choices,
style=wx.CB_READONLY, size=(50, -1))
self.pen_width_combo.SetToolTipString(_(u"Border width"))
self.AddControl(self.pen_width_combo)
self.Bind(wx.EVT_COMBOBOX, self.OnLineWidth, self.pen_width_combo)
|
python
|
def _create_penwidth_combo(self):
"""Create pen width combo box"""
choices = map(unicode, xrange(12))
self.pen_width_combo = \
_widgets.PenWidthComboBox(self, choices=choices,
style=wx.CB_READONLY, size=(50, -1))
self.pen_width_combo.SetToolTipString(_(u"Border width"))
self.AddControl(self.pen_width_combo)
self.Bind(wx.EVT_COMBOBOX, self.OnLineWidth, self.pen_width_combo)
|
[
"def",
"_create_penwidth_combo",
"(",
"self",
")",
":",
"choices",
"=",
"map",
"(",
"unicode",
",",
"xrange",
"(",
"12",
")",
")",
"self",
".",
"pen_width_combo",
"=",
"_widgets",
".",
"PenWidthComboBox",
"(",
"self",
",",
"choices",
"=",
"choices",
",",
"style",
"=",
"wx",
".",
"CB_READONLY",
",",
"size",
"=",
"(",
"50",
",",
"-",
"1",
")",
")",
"self",
".",
"pen_width_combo",
".",
"SetToolTipString",
"(",
"_",
"(",
"u\"Border width\"",
")",
")",
"self",
".",
"AddControl",
"(",
"self",
".",
"pen_width_combo",
")",
"self",
".",
"Bind",
"(",
"wx",
".",
"EVT_COMBOBOX",
",",
"self",
".",
"OnLineWidth",
",",
"self",
".",
"pen_width_combo",
")"
] |
Create pen width combo box
|
[
"Create",
"pen",
"width",
"combo",
"box"
] |
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
|
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_toolbars.py#L667-L677
|
236,292
|
manns/pyspread
|
pyspread/src/gui/_toolbars.py
|
AttributesToolbar._create_color_buttons
|
def _create_color_buttons(self):
"""Create color choice buttons"""
button_size = (30, 30)
button_style = wx.NO_BORDER
try:
self.linecolor_choice = \
csel.ColourSelect(self, -1, unichr(0x2500), (0, 0, 0),
size=button_size, style=button_style)
except UnicodeEncodeError:
# ANSI wxPython installed
self.linecolor_choice = \
csel.ColourSelect(self, -1, "-", (0, 0, 0),
size=button_size, style=button_style)
self.bgcolor_choice = \
csel.ColourSelect(self, -1, "", (255, 255, 255),
size=button_size, style=button_style)
self.textcolor_choice = \
csel.ColourSelect(self, -1, "A", (0, 0, 0),
size=button_size, style=button_style)
self.linecolor_choice.SetToolTipString(_(u"Border line color"))
self.bgcolor_choice.SetToolTipString(_(u"Cell background"))
self.textcolor_choice.SetToolTipString(_(u"Text color"))
self.AddControl(self.linecolor_choice)
self.AddControl(self.bgcolor_choice)
self.AddControl(self.textcolor_choice)
self.linecolor_choice.Bind(csel.EVT_COLOURSELECT, self.OnLineColor)
self.bgcolor_choice.Bind(csel.EVT_COLOURSELECT, self.OnBGColor)
self.textcolor_choice.Bind(csel.EVT_COLOURSELECT, self.OnTextColor)
|
python
|
def _create_color_buttons(self):
"""Create color choice buttons"""
button_size = (30, 30)
button_style = wx.NO_BORDER
try:
self.linecolor_choice = \
csel.ColourSelect(self, -1, unichr(0x2500), (0, 0, 0),
size=button_size, style=button_style)
except UnicodeEncodeError:
# ANSI wxPython installed
self.linecolor_choice = \
csel.ColourSelect(self, -1, "-", (0, 0, 0),
size=button_size, style=button_style)
self.bgcolor_choice = \
csel.ColourSelect(self, -1, "", (255, 255, 255),
size=button_size, style=button_style)
self.textcolor_choice = \
csel.ColourSelect(self, -1, "A", (0, 0, 0),
size=button_size, style=button_style)
self.linecolor_choice.SetToolTipString(_(u"Border line color"))
self.bgcolor_choice.SetToolTipString(_(u"Cell background"))
self.textcolor_choice.SetToolTipString(_(u"Text color"))
self.AddControl(self.linecolor_choice)
self.AddControl(self.bgcolor_choice)
self.AddControl(self.textcolor_choice)
self.linecolor_choice.Bind(csel.EVT_COLOURSELECT, self.OnLineColor)
self.bgcolor_choice.Bind(csel.EVT_COLOURSELECT, self.OnBGColor)
self.textcolor_choice.Bind(csel.EVT_COLOURSELECT, self.OnTextColor)
|
[
"def",
"_create_color_buttons",
"(",
"self",
")",
":",
"button_size",
"=",
"(",
"30",
",",
"30",
")",
"button_style",
"=",
"wx",
".",
"NO_BORDER",
"try",
":",
"self",
".",
"linecolor_choice",
"=",
"csel",
".",
"ColourSelect",
"(",
"self",
",",
"-",
"1",
",",
"unichr",
"(",
"0x2500",
")",
",",
"(",
"0",
",",
"0",
",",
"0",
")",
",",
"size",
"=",
"button_size",
",",
"style",
"=",
"button_style",
")",
"except",
"UnicodeEncodeError",
":",
"# ANSI wxPython installed",
"self",
".",
"linecolor_choice",
"=",
"csel",
".",
"ColourSelect",
"(",
"self",
",",
"-",
"1",
",",
"\"-\"",
",",
"(",
"0",
",",
"0",
",",
"0",
")",
",",
"size",
"=",
"button_size",
",",
"style",
"=",
"button_style",
")",
"self",
".",
"bgcolor_choice",
"=",
"csel",
".",
"ColourSelect",
"(",
"self",
",",
"-",
"1",
",",
"\"\"",
",",
"(",
"255",
",",
"255",
",",
"255",
")",
",",
"size",
"=",
"button_size",
",",
"style",
"=",
"button_style",
")",
"self",
".",
"textcolor_choice",
"=",
"csel",
".",
"ColourSelect",
"(",
"self",
",",
"-",
"1",
",",
"\"A\"",
",",
"(",
"0",
",",
"0",
",",
"0",
")",
",",
"size",
"=",
"button_size",
",",
"style",
"=",
"button_style",
")",
"self",
".",
"linecolor_choice",
".",
"SetToolTipString",
"(",
"_",
"(",
"u\"Border line color\"",
")",
")",
"self",
".",
"bgcolor_choice",
".",
"SetToolTipString",
"(",
"_",
"(",
"u\"Cell background\"",
")",
")",
"self",
".",
"textcolor_choice",
".",
"SetToolTipString",
"(",
"_",
"(",
"u\"Text color\"",
")",
")",
"self",
".",
"AddControl",
"(",
"self",
".",
"linecolor_choice",
")",
"self",
".",
"AddControl",
"(",
"self",
".",
"bgcolor_choice",
")",
"self",
".",
"AddControl",
"(",
"self",
".",
"textcolor_choice",
")",
"self",
".",
"linecolor_choice",
".",
"Bind",
"(",
"csel",
".",
"EVT_COLOURSELECT",
",",
"self",
".",
"OnLineColor",
")",
"self",
".",
"bgcolor_choice",
".",
"Bind",
"(",
"csel",
".",
"EVT_COLOURSELECT",
",",
"self",
".",
"OnBGColor",
")",
"self",
".",
"textcolor_choice",
".",
"Bind",
"(",
"csel",
".",
"EVT_COLOURSELECT",
",",
"self",
".",
"OnTextColor",
")"
] |
Create color choice buttons
|
[
"Create",
"color",
"choice",
"buttons"
] |
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
|
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_toolbars.py#L679-L712
|
236,293
|
manns/pyspread
|
pyspread/src/gui/_toolbars.py
|
AttributesToolbar._create_merge_button
|
def _create_merge_button(self):
"""Create merge button"""
bmp = icons["Merge"]
self.mergetool_id = wx.NewId()
self.AddCheckTool(self.mergetool_id, "Merge", bmp, bmp,
short_help_string=_("Merge cells"))
self.Bind(wx.EVT_TOOL, self.OnMerge, id=self.mergetool_id)
|
python
|
def _create_merge_button(self):
"""Create merge button"""
bmp = icons["Merge"]
self.mergetool_id = wx.NewId()
self.AddCheckTool(self.mergetool_id, "Merge", bmp, bmp,
short_help_string=_("Merge cells"))
self.Bind(wx.EVT_TOOL, self.OnMerge, id=self.mergetool_id)
|
[
"def",
"_create_merge_button",
"(",
"self",
")",
":",
"bmp",
"=",
"icons",
"[",
"\"Merge\"",
"]",
"self",
".",
"mergetool_id",
"=",
"wx",
".",
"NewId",
"(",
")",
"self",
".",
"AddCheckTool",
"(",
"self",
".",
"mergetool_id",
",",
"\"Merge\"",
",",
"bmp",
",",
"bmp",
",",
"short_help_string",
"=",
"_",
"(",
"\"Merge cells\"",
")",
")",
"self",
".",
"Bind",
"(",
"wx",
".",
"EVT_TOOL",
",",
"self",
".",
"OnMerge",
",",
"id",
"=",
"self",
".",
"mergetool_id",
")"
] |
Create merge button
|
[
"Create",
"merge",
"button"
] |
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
|
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_toolbars.py#L714-L721
|
236,294
|
manns/pyspread
|
pyspread/src/gui/_toolbars.py
|
AttributesToolbar._update_font
|
def _update_font(self, textfont):
"""Updates text font widget
Parameters
----------
textfont: String
\tFont name
"""
try:
fontface_id = self.fonts.index(textfont)
except ValueError:
fontface_id = 0
self.font_choice_combo.Select(fontface_id)
|
python
|
def _update_font(self, textfont):
"""Updates text font widget
Parameters
----------
textfont: String
\tFont name
"""
try:
fontface_id = self.fonts.index(textfont)
except ValueError:
fontface_id = 0
self.font_choice_combo.Select(fontface_id)
|
[
"def",
"_update_font",
"(",
"self",
",",
"textfont",
")",
":",
"try",
":",
"fontface_id",
"=",
"self",
".",
"fonts",
".",
"index",
"(",
"textfont",
")",
"except",
"ValueError",
":",
"fontface_id",
"=",
"0",
"self",
".",
"font_choice_combo",
".",
"Select",
"(",
"fontface_id",
")"
] |
Updates text font widget
Parameters
----------
textfont: String
\tFont name
|
[
"Updates",
"text",
"font",
"widget"
] |
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
|
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_toolbars.py#L726-L742
|
236,295
|
manns/pyspread
|
pyspread/src/gui/_toolbars.py
|
AttributesToolbar._update_font_weight
|
def _update_font_weight(self, font_weight):
"""Updates font weight widget
Parameters
----------
font_weight: Integer
\tButton down iif font_weight == wx.FONTWEIGHT_BOLD
"""
toggle_state = font_weight & wx.FONTWEIGHT_BOLD == wx.FONTWEIGHT_BOLD
self.ToggleTool(wx.FONTFLAG_BOLD, toggle_state)
|
python
|
def _update_font_weight(self, font_weight):
"""Updates font weight widget
Parameters
----------
font_weight: Integer
\tButton down iif font_weight == wx.FONTWEIGHT_BOLD
"""
toggle_state = font_weight & wx.FONTWEIGHT_BOLD == wx.FONTWEIGHT_BOLD
self.ToggleTool(wx.FONTFLAG_BOLD, toggle_state)
|
[
"def",
"_update_font_weight",
"(",
"self",
",",
"font_weight",
")",
":",
"toggle_state",
"=",
"font_weight",
"&",
"wx",
".",
"FONTWEIGHT_BOLD",
"==",
"wx",
".",
"FONTWEIGHT_BOLD",
"self",
".",
"ToggleTool",
"(",
"wx",
".",
"FONTFLAG_BOLD",
",",
"toggle_state",
")"
] |
Updates font weight widget
Parameters
----------
font_weight: Integer
\tButton down iif font_weight == wx.FONTWEIGHT_BOLD
|
[
"Updates",
"font",
"weight",
"widget"
] |
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
|
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_toolbars.py#L757-L770
|
236,296
|
manns/pyspread
|
pyspread/src/gui/_toolbars.py
|
AttributesToolbar._update_font_style
|
def _update_font_style(self, font_style):
"""Updates font style widget
Parameters
----------
font_style: Integer
\tButton down iif font_style == wx.FONTSTYLE_ITALIC
"""
toggle_state = font_style & wx.FONTSTYLE_ITALIC == wx.FONTSTYLE_ITALIC
self.ToggleTool(wx.FONTFLAG_ITALIC, toggle_state)
|
python
|
def _update_font_style(self, font_style):
"""Updates font style widget
Parameters
----------
font_style: Integer
\tButton down iif font_style == wx.FONTSTYLE_ITALIC
"""
toggle_state = font_style & wx.FONTSTYLE_ITALIC == wx.FONTSTYLE_ITALIC
self.ToggleTool(wx.FONTFLAG_ITALIC, toggle_state)
|
[
"def",
"_update_font_style",
"(",
"self",
",",
"font_style",
")",
":",
"toggle_state",
"=",
"font_style",
"&",
"wx",
".",
"FONTSTYLE_ITALIC",
"==",
"wx",
".",
"FONTSTYLE_ITALIC",
"self",
".",
"ToggleTool",
"(",
"wx",
".",
"FONTFLAG_ITALIC",
",",
"toggle_state",
")"
] |
Updates font style widget
Parameters
----------
font_style: Integer
\tButton down iif font_style == wx.FONTSTYLE_ITALIC
|
[
"Updates",
"font",
"style",
"widget"
] |
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
|
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_toolbars.py#L772-L785
|
236,297
|
manns/pyspread
|
pyspread/src/gui/_toolbars.py
|
AttributesToolbar._update_frozencell
|
def _update_frozencell(self, frozen):
"""Updates frozen cell widget
Parameters
----------
frozen: Bool or string
\tUntoggled iif False
"""
toggle_state = frozen is not False
self.ToggleTool(wx.FONTFLAG_MASK, toggle_state)
|
python
|
def _update_frozencell(self, frozen):
"""Updates frozen cell widget
Parameters
----------
frozen: Bool or string
\tUntoggled iif False
"""
toggle_state = frozen is not False
self.ToggleTool(wx.FONTFLAG_MASK, toggle_state)
|
[
"def",
"_update_frozencell",
"(",
"self",
",",
"frozen",
")",
":",
"toggle_state",
"=",
"frozen",
"is",
"not",
"False",
"self",
".",
"ToggleTool",
"(",
"wx",
".",
"FONTFLAG_MASK",
",",
"toggle_state",
")"
] |
Updates frozen cell widget
Parameters
----------
frozen: Bool or string
\tUntoggled iif False
|
[
"Updates",
"frozen",
"cell",
"widget"
] |
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
|
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_toolbars.py#L787-L800
|
236,298
|
manns/pyspread
|
pyspread/src/gui/_toolbars.py
|
AttributesToolbar._update_textrotation
|
def _update_textrotation(self, angle):
"""Updates text rotation toggle button"""
states = {0: 0, -90: 1, 180: 2, 90: 3}
try:
self.rotation_tb.state = states[round(angle)]
except KeyError:
self.rotation_tb.state = 0
self.rotation_tb.toggle(None)
self.rotation_tb.Refresh()
|
python
|
def _update_textrotation(self, angle):
"""Updates text rotation toggle button"""
states = {0: 0, -90: 1, 180: 2, 90: 3}
try:
self.rotation_tb.state = states[round(angle)]
except KeyError:
self.rotation_tb.state = 0
self.rotation_tb.toggle(None)
self.rotation_tb.Refresh()
|
[
"def",
"_update_textrotation",
"(",
"self",
",",
"angle",
")",
":",
"states",
"=",
"{",
"0",
":",
"0",
",",
"-",
"90",
":",
"1",
",",
"180",
":",
"2",
",",
"90",
":",
"3",
"}",
"try",
":",
"self",
".",
"rotation_tb",
".",
"state",
"=",
"states",
"[",
"round",
"(",
"angle",
")",
"]",
"except",
"KeyError",
":",
"self",
".",
"rotation_tb",
".",
"state",
"=",
"0",
"self",
".",
"rotation_tb",
".",
"toggle",
"(",
"None",
")",
"self",
".",
"rotation_tb",
".",
"Refresh",
"(",
")"
] |
Updates text rotation toggle button
|
[
"Updates",
"text",
"rotation",
"toggle",
"button"
] |
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
|
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_toolbars.py#L854-L865
|
236,299
|
manns/pyspread
|
pyspread/src/gui/_toolbars.py
|
AttributesToolbar._update_justification
|
def _update_justification(self, justification):
"""Updates horizontal text justification button
Parameters
----------
justification: String in ["left", "center", "right"]
\tSwitches button to untoggled if False and toggled if True
"""
states = {"left": 2, "center": 0, "right": 1}
self.justify_tb.state = states[justification]
self.justify_tb.toggle(None)
self.justify_tb.Refresh()
|
python
|
def _update_justification(self, justification):
"""Updates horizontal text justification button
Parameters
----------
justification: String in ["left", "center", "right"]
\tSwitches button to untoggled if False and toggled if True
"""
states = {"left": 2, "center": 0, "right": 1}
self.justify_tb.state = states[justification]
self.justify_tb.toggle(None)
self.justify_tb.Refresh()
|
[
"def",
"_update_justification",
"(",
"self",
",",
"justification",
")",
":",
"states",
"=",
"{",
"\"left\"",
":",
"2",
",",
"\"center\"",
":",
"0",
",",
"\"right\"",
":",
"1",
"}",
"self",
".",
"justify_tb",
".",
"state",
"=",
"states",
"[",
"justification",
"]",
"self",
".",
"justify_tb",
".",
"toggle",
"(",
"None",
")",
"self",
".",
"justify_tb",
".",
"Refresh",
"(",
")"
] |
Updates horizontal text justification button
Parameters
----------
justification: String in ["left", "center", "right"]
\tSwitches button to untoggled if False and toggled if True
|
[
"Updates",
"horizontal",
"text",
"justification",
"button"
] |
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
|
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_toolbars.py#L867-L883
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.