_id
stringlengths
2
7
title
stringlengths
1
88
partition
stringclasses
3 values
text
stringlengths
75
19.8k
language
stringclasses
1 value
meta_information
dict
q231500
JLinkDeviceInfo.name
train
def name(self): """Returns the name of the device. Args: self (JLinkDeviceInfo): the ``JLinkDeviceInfo`` instance Returns: Device name. """ return ctypes.cast(self.sName, ctypes.c_char_p).value.decode()
python
{ "resource": "" }
q231501
JLinkDeviceInfo.manufacturer
train
def manufacturer(self): """Returns the name of the manufacturer of the device. Args: self (JLinkDeviceInfo): the ``JLinkDeviceInfo`` instance Returns: Manufacturer name. """ buf = ctypes.cast(self.sManu, ctypes.c_char_p).value return buf.decode() if ...
python
{ "resource": "" }
q231502
JLinkBreakpointInfo.software_breakpoint
train
def software_breakpoint(self): """Returns whether this is a software breakpoint. Args: self (JLinkBreakpointInfo): the ``JLinkBreakpointInfo`` instance Returns: ``True`` if the breakpoint is a software breakpoint, otherwise ``False``. """ software_...
python
{ "resource": "" }
q231503
Library.find_library_windows
train
def find_library_windows(cls): """Loads the SEGGER DLL from the windows installation directory. On Windows, these are found either under: - ``C:\\Program Files\\SEGGER\\JLink`` - ``C:\\Program Files (x86)\\SEGGER\\JLink``. Args: cls (Library): the ``Library`` clas...
python
{ "resource": "" }
q231504
Library.find_library_linux
train
def find_library_linux(cls): """Loads the SEGGER DLL from the root directory. On Linux, the SEGGER tools are installed under the ``/opt/SEGGER`` directory with versioned directories having the suffix ``_VERSION``. Args: cls (Library): the ``Library`` class Returns: ...
python
{ "resource": "" }
q231505
Library.find_library_darwin
train
def find_library_darwin(cls): """Loads the SEGGER DLL from the installed applications. This method accounts for the all the different ways in which the DLL may be installed depending on the version of the DLL. Always uses the first directory found. SEGGER's DLL is installed in...
python
{ "resource": "" }
q231506
Library.load_default
train
def load_default(self): """Loads the default J-Link SDK DLL. The default J-Link SDK is determined by first checking if ``ctypes`` can find the DLL, then by searching the platform-specific paths. Args: self (Library): the ``Library`` instance Returns: ``True...
python
{ "resource": "" }
q231507
Library.load
train
def load(self, path=None): """Loads the specified DLL, if any, otherwise re-loads the current DLL. If ``path`` is specified, loads the DLL at the given ``path``, otherwise re-loads the DLL currently specified by this library. Note: This creates a temporary DLL file to use for...
python
{ "resource": "" }
q231508
Library.unload
train
def unload(self): """Unloads the library's DLL if it has been loaded. This additionally cleans up the temporary DLL file that was created when the library was loaded. Args: self (Library): the ``Library`` instance Returns: ``True`` if the DLL was unloaded, ...
python
{ "resource": "" }
q231509
_open
train
def _open(filename=None, mode='r'): """Open a file or ``sys.stdout`` depending on the provided filename. Args: filename (str): The path to the file that should be opened. If ``None`` or ``'-'``, ``sys.stdout`` or ``sys.stdin`` is returned depending on the desired mode. Defaults ...
python
{ "resource": "" }
q231510
get_pkg_names
train
def get_pkg_names(pkgs): """Get PyPI package names from a list of imports. Args: pkgs (List[str]): List of import names. Returns: List[str]: The corresponding PyPI package names. """ result = set() with open(join("mapping"), "r") as f: data = dict(x.strip().split(":") ...
python
{ "resource": "" }
q231511
charmap
train
def charmap(prefixed_name): """ Return the character map used for a given font. Returns ------- return_value: dict The dictionary mapping the icon names to the corresponding unicode character. """ prefix, name = prefixed_name.split('.') return _instance().charmap[prefix][name]
python
{ "resource": "" }
q231512
set_global_defaults
train
def set_global_defaults(**kwargs): """Set global defaults for the options passed to the icon painter.""" valid_options = [ 'active', 'selected', 'disabled', 'on', 'off', 'on_active', 'on_selected', 'on_disabled', 'off_active', 'off_selected', 'off_disabled', 'color', 'color_on',...
python
{ "resource": "" }
q231513
CharIconPainter.paint
train
def paint(self, iconic, painter, rect, mode, state, options): """Main paint method.""" for opt in options: self._paint_icon(iconic, painter, rect, mode, state, opt)
python
{ "resource": "" }
q231514
CharIconPainter._paint_icon
train
def _paint_icon(self, iconic, painter, rect, mode, state, options): """Paint a single icon.""" painter.save() color = options['color'] char = options['char'] color_options = { QIcon.On: { QIcon.Normal: (options['color_on'], options['on']), ...
python
{ "resource": "" }
q231515
IconicFont.icon
train
def icon(self, *names, **kwargs): """Return a QIcon object corresponding to the provided icon name.""" cache_key = '{}{}'.format(names,kwargs) if cache_key not in self.icon_cache: options_list = kwargs.pop('options', [{}] * len(names)) general_options = kwargs ...
python
{ "resource": "" }
q231516
IconicFont.font
train
def font(self, prefix, size): """Return a QFont corresponding to the given prefix and size.""" font = QFont(self.fontname[prefix]) font.setPixelSize(size) if prefix[-1] == 's': # solid style font.setStyleName('Solid') return font
python
{ "resource": "" }
q231517
IconicFont._custom_icon
train
def _custom_icon(self, name, **kwargs): """Return the custom icon corresponding to the given name.""" options = dict(_default_options, **kwargs) if name in self.painters: painter = self.painters[name] return self._icon_by_painter(painter, options) else: ...
python
{ "resource": "" }
q231518
IconicFont._icon_by_painter
train
def _icon_by_painter(self, painter, options): """Return the icon corresponding to the given painter.""" engine = CharIconEngine(self, painter, options) return QIcon(engine)
python
{ "resource": "" }
q231519
UpdateFA5Command.finalize_options
train
def finalize_options(self): """Validate the command options.""" assert bool(self.fa_version), 'FA version is mandatory for this command.' if self.zip_path: assert os.path.exists(self.zip_path), ( 'Local zipfile does not exist: %s' % self.zip_path)
python
{ "resource": "" }
q231520
UpdateFA5Command.__print
train
def __print(self, msg): """Shortcut for printing with the distutils logger.""" self.announce(msg, level=distutils.log.INFO)
python
{ "resource": "" }
q231521
UpdateFA5Command.__zip_file
train
def __zip_file(self): """Get a file object of the FA zip file.""" if self.zip_path: # If using a local file, just open it: self.__print('Opening local zipfile: %s' % self.zip_path) return open(self.zip_path, 'rb') # Otherwise, download it and make a file obje...
python
{ "resource": "" }
q231522
UpdateFA5Command.__zipped_files_data
train
def __zipped_files_data(self): """Get a dict of all files of interest from the FA release zipfile.""" files = {} with zipfile.ZipFile(self.__zip_file) as thezip: for zipinfo in thezip.infolist(): if zipinfo.filename.endswith('metadata/icons.json'): ...
python
{ "resource": "" }
q231523
from_string
train
def from_string(proto_str): ''' Produce a Protobuf module from a string description. Return the module if successfully compiled, otherwise raise a BadProtobuf exception. ''' _, proto_file = tempfile.mkstemp(suffix='.proto') with open(proto_file, 'w+') as proto_f: proto_f....
python
{ "resource": "" }
q231524
_load_module
train
def _load_module(path): 'Helper to load a Python file at path and return as a module' module_name = os.path.splitext(os.path.basename(path))[0] module = None if sys.version_info.minor < 5: loader = importlib.machinery.SourceFileLoader(module_name, path) module = loader.load_mod...
python
{ "resource": "" }
q231525
_compile_proto
train
def _compile_proto(full_path, dest): 'Helper to compile protobuf files' proto_path = os.path.dirname(full_path) protoc_args = [find_protoc(), '--python_out={}'.format(dest), '--proto_path={}'.format(proto_path), full_path] proc = subprocess...
python
{ "resource": "" }
q231526
from_file
train
def from_file(proto_file): ''' Take a filename |protoc_file|, compile it via the Protobuf compiler, and import the module. Return the module if successfully compiled, otherwise raise either a ProtocNotFound or BadProtobuf exception. ''' if not proto_file.endswith('.proto'): ...
python
{ "resource": "" }
q231527
types_from_module
train
def types_from_module(pb_module): ''' Return protobuf class types from an imported generated module. ''' types = pb_module.DESCRIPTOR.message_types_by_name return [getattr(pb_module, name) for name in types]
python
{ "resource": "" }
q231528
Permuter._resolve_child
train
def _resolve_child(self, path): 'Return a member generator by a dot-delimited path' obj = self for component in path.split('.'): ptr = obj if not isinstance(ptr, Permuter): raise self.MessageNotFound("Bad element path [wrong type]") # pylint:...
python
{ "resource": "" }
q231529
Permuter.make_dependent
train
def make_dependent(self, source, target, action): ''' Create a dependency between path 'source' and path 'target' via the callable 'action'. >>> permuter._generators [IterValueGenerator(one), IterValueGenerator(two)] >>> permuter.make_dependent('one', 'two', lambda x: x ...
python
{ "resource": "" }
q231530
Permuter.get
train
def get(self): 'Retrieve the most recent value generated' # If you attempt to use a generator comprehension below, it will # consume the StopIteration exception and just return an empty tuple, # instead of stopping iteration normally return tuple([(x.name(), x.get()) for x in sel...
python
{ "resource": "" }
q231531
_fuzzdb_integers
train
def _fuzzdb_integers(limit=0): 'Helper to grab some integers from fuzzdb' path = os.path.join(BASE_PATH, 'integer-overflow/integer-overflows.txt') stream = _open_fuzzdb_file(path) for line in _limit_helper(stream, limit): yield int(line.decode('utf-8'), 0)
python
{ "resource": "" }
q231532
_fuzzdb_get_strings
train
def _fuzzdb_get_strings(max_len=0): 'Helper to get all the strings from fuzzdb' ignored = ['integer-overflow'] for subdir in pkg_resources.resource_listdir('protofuzz', BASE_PATH): if subdir in ignored: continue path = '{}/{}'.format(BASE_PATH, subdir) listing = pkg_re...
python
{ "resource": "" }
q231533
get_integers
train
def get_integers(bitwidth, unsigned, limit=0): ''' Get integers from fuzzdb database bitwidth - The bitwidth that has to contain the integer unsigned - Whether the type is unsigned limit - Limit to |limit| results ''' if unsigned: start, stop = 0, ((1 << bitwidth) - 1) els...
python
{ "resource": "" }
q231534
get_floats
train
def get_floats(bitwidth, limit=0): ''' Return a number of interesting floating point values ''' assert bitwidth in (32, 64, 80) values = [0.0, -1.0, 1.0, -1231231231231.0123, 123123123123123.123] for val in _limit_helper(values, limit): yield val
python
{ "resource": "" }
q231535
_int_generator
train
def _int_generator(descriptor, bitwidth, unsigned): 'Helper to create a basic integer value generator' vals = list(values.get_integers(bitwidth, unsigned)) return gen.IterValueGenerator(descriptor.name, vals)
python
{ "resource": "" }
q231536
_string_generator
train
def _string_generator(descriptor, max_length=0, limit=0): 'Helper to create a string generator' vals = list(values.get_strings(max_length, limit)) return gen.IterValueGenerator(descriptor.name, vals)
python
{ "resource": "" }
q231537
_float_generator
train
def _float_generator(descriptor, bitwidth): 'Helper to create floating point values' return gen.IterValueGenerator(descriptor.name, values.get_floats(bitwidth))
python
{ "resource": "" }
q231538
_enum_generator
train
def _enum_generator(descriptor): 'Helper to create protobuf enums' vals = descriptor.enum_type.values_by_number.keys() return gen.IterValueGenerator(descriptor.name, vals)
python
{ "resource": "" }
q231539
_prototype_to_generator
train
def _prototype_to_generator(descriptor, cls): 'Helper to map a descriptor to a protofuzz generator' _fd = D.FieldDescriptor generator = None ints32 = [_fd.TYPE_INT32, _fd.TYPE_UINT32, _fd.TYPE_FIXED32, _fd.TYPE_SFIXED32, _fd.TYPE_SINT32] ints64 = [_fd.TYPE_INT64, _fd.TYPE_UINT64, _fd....
python
{ "resource": "" }
q231540
descriptor_to_generator
train
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: genera...
python
{ "resource": "" }
q231541
_assign_to_field
train
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 = ta...
python
{ "resource": "" }
q231542
_fields_to_object
train
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[na...
python
{ "resource": "" }
q231543
_module_to_generators
train
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: ProtobufGe...
python
{ "resource": "" }
q231544
ProtobufGenerator.add_dependency
train
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 uint...
python
{ "resource": "" }
q231545
Compare.print_report
train
def print_report(self): """ Print Compare report. :return: None """ report = compare_report_print( self.sorted, self.scores, self.best_name) print(report)
python
{ "resource": "" }
q231546
F_calc
train
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: ...
python
{ "resource": "" }
q231547
G_calc
train
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 exce...
python
{ "resource": "" }
q231548
RACC_calc
train
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) ret...
python
{ "resource": "" }
q231549
CEN_misclassification_calc
train
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 : in...
python
{ "resource": "" }
q231550
html_init
train
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 += "<b...
python
{ "resource": "" }
q231551
html_dataset_type
train
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 :re...
python
{ "resource": "" }
q231552
color_check
train
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)): re...
python
{ "resource": "" }
q231553
html_table_color
train
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] """...
python
{ "resource": "" }
q231554
html_table
train
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 normali...
python
{ "resource": "" }
q231555
html_overall_stat
train
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 i...
python
{ "resource": "" }
q231556
html_class_stat
train
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: sca...
python
{ "resource": "" }
q231557
table_print
train
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....
python
{ "resource": "" }
q231558
csv_matrix_print
train
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]...
python
{ "resource": "" }
q231559
csv_print
train
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 ...
python
{ "resource": "" }
q231560
stat_print
train
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 clas...
python
{ "resource": "" }
q231561
compare_report_print
train
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 ...
python
{ "resource": "" }
q231562
online_help
train
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 + ...
python
{ "resource": "" }
q231563
rounder
train
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 """ ...
python
{ "resource": "" }
q231564
class_filter
train
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_n...
python
{ "resource": "" }
q231565
vector_check
train
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
{ "resource": "" }
q231566
matrix_check
train
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( ...
python
{ "resource": "" }
q231567
vector_filter
train
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 = ...
python
{ "resource": "" }
q231568
class_check
train
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
{ "resource": "" }
q231569
one_vs_all_func
train
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 al...
python
{ "resource": "" }
q231570
normalized_table_calc
train
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 ...
python
{ "resource": "" }
q231571
transpose_func
train
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 enumerat...
python
{ "resource": "" }
q231572
matrix_params_from_table
train
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()) ...
python
{ "resource": "" }
q231573
matrix_params_calc
train
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 :typ...
python
{ "resource": "" }
q231574
imbalance_check
train
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_valu...
python
{ "resource": "" }
q231575
binary_check
train
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
{ "resource": "" }
q231576
statistic_recommend
train
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 imbal...
python
{ "resource": "" }
q231577
print_result
train
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...
python
{ "resource": "" }
q231578
AUNP_calc
train
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 ...
python
{ "resource": "" }
q231579
overall_MCC_calc
train
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: Overal...
python
{ "resource": "" }
q231580
convex_combination
train
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: con...
python
{ "resource": "" }
q231581
ncr
train
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
{ "resource": "" }
q231582
p_value_calc
train
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())) ...
python
{ "resource": "" }
q231583
hamming_calc
train
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: ...
python
{ "resource": "" }
q231584
zero_one_loss_calc
train
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: retu...
python
{ "resource": "" }
q231585
entropy_calc
train
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(): lik...
python
{ "resource": "" }
q231586
cross_entropy_calc
train
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 ...
python
{ "resource": "" }
q231587
joint_entropy_calc
train
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: ...
python
{ "resource": "" }
q231588
conditional_entropy_calc
train
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...
python
{ "resource": "" }
q231589
lambda_B_calc
train
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 ...
python
{ "resource": "" }
q231590
lambda_A_calc
train
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...
python
{ "resource": "" }
q231591
chi_square_calc
train
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 :typ...
python
{ "resource": "" }
q231592
kappa_se_calc
train
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...
python
{ "resource": "" }
q231593
micro_calc
train
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...
python
{ "resource": "" }
q231594
macro_calc
train
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: ...
python
{ "resource": "" }
q231595
PC_PI_calc
train
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: ...
python
{ "resource": "" }
q231596
PC_AC1_calc
train
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: ...
python
{ "resource": "" }
q231597
overall_jaccard_index_calc
train
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 = jacc...
python
{ "resource": "" }
q231598
overall_accuracy_calc
train
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 ...
python
{ "resource": "" }
q231599
AUC_analysis
train
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 ...
python
{ "resource": "" }