Returns the percent match for the specified prediction call; requires
    that the data was split before using an analyzed method.

    Args:
        out (dict): output dictionary to save the result to.
970201
def _percent_match(result, out, yP=None, *argl):
    
    if len(argl) > 1:
        if yP is None:
            Xt = argl[1]
            key = id(Xt)
            if key in _splits:
                yP = _splits[key][3]
                
        if yP is not None:
            import math
            out["%"] = round(1.-sum(abs(yP - result))/float(len(result)), 3)
390835
def valueAt(self, percent):
        
        values = self.values()
        if percent < 0:
            index = 0
        elif percent > 1:
            index = -1
        else:
            index = percent * (len(values) - 1)
        
        # allow some floating point errors for the index (30% left or right)
        remain = index % 1
        if remain < 0.3 or 0.7 < remain:
            try:
                return values[int(round(index))]
            except IndexError:
                return None
        return None
844664
def _xfs_estimate_output(out):
    '''
    
    '''
    spc = re.compile(r"\s+")
    data = {}
    for line in [l for l in out.split("\n") if l.strip()][1:]:
        directory, bsize, blocks, megabytes, logsize = spc.sub(" ", line).split(" ")
        data[directory] = {
            'block _size': bsize,
            'blocks': blocks,
            'megabytes': megabytes,
            'logsize': logsize,
        }

    return data
119319
def _call(self, x, out=None):
        
        if out is None:
            return x.interpolation
        else:
            out.sampling(x.interpolation)
350534
def from_percent(position_percent):
        """"""
        if not isinstance(position_percent, int):
            raise PyVLXException("Position::position_percent_has_to_be_int")
        if position_percent < 0:
            raise PyVLXException("Position::position_percent_has_to_be_positive")
        if position_percent > 100:
            raise PyVLXException("Position::position_percent_out_of_range")
        return bytes([position_percent*2, 0])
904144
def _generate_out_list(results):
    '''
    
    '''
    passed = 0
    failed = 0
    skipped = 0
    missing_tests = 0
    total_time = 0.0
    for state in results:
        if not results[state].items():
            missing_tests = missing_tests + 1
        else:
            for dummy, val in results[state].items():
                log.info("dummy=%s, val=%s", dummy, val)
                if val['status'].startswith('Pass'):
                    passed = passed + 1
                if val['status'].startswith('Fail'):
                    failed = failed + 1
                if val['status'].startswith('Skip'):
                    skipped = skipped + 1
                total_time = total_time + float(val['duration'])
    out_list = []
    for key, value in results.items():
        out_list.append({key: value})
    out_list.sort()
    out_list.append({'TEST RESULTS': {'Execution Time': round(total_time, 4),
                                      'Passed': passed, 'Failed': failed, 'Skipped': skipped,
                                      'Missing Tests': missing_tests}})
    return out_list
421313
def _percent_match(date_classes, tokens):
    
    match_count = [0] * len(date_classes)

    for i, date_class in enumerate(date_classes):
        for token in tokens:
            if date_class.is_match(token):
                match_count[i] += 1

    percentages = tuple([float(m) / len(tokens) for m in match_count])
    return percentages
756756
def _compare_expected(expected, output, sess, onnx, decimal=5, onnx_shape=None, **kwargs):
    
    tested = 0
    if isinstance(expected, list):
        if isinstance(output, list):
            onnx_shapes = [_.shape for _ in sess.get_outputs()]
            if 'Out0' in kwargs:
                expected = expected[:1]
                output = output[:1]
                del kwargs['Out0']
            if 'Reshape' in kwargs:
                del kwargs['Reshape']
                output = numpy.hstack(output).ravel()
                output = output.reshape((len(expected),
                                         len(output.ravel()) // len(expected)))
            if len(expected) != len(output):
                raise OnnxRuntimeAssertionError("Unexpected number of outputs '{0}', expected={1}, got={2}".format(onnx, len(expected), len(output)))
            for exp, out, osh in zip(expected, output, onnx_shapes):
                _compare_expected(exp, out, sess, onnx, decimal=decimal, onnx_shape=osh, **kwargs)
                tested += 1
        else:
            raise OnnxRuntimeAssertionError("Type mismatch for '{0}', output type is {1}".format(onnx, type(output)))
    elif isinstance(expected, dict):
        if not isinstance(output, dict):
            raise OnnxRuntimeAssertionError("Type mismatch for '{0}'".format(onnx))
        for k, v in output.items():
            if k not in expected:
                continue
            msg = compare_outputs(expected[k], v, decimal=decimal, **kwargs)
            if msg:
                raise OnnxRuntimeAssertionError("Unexpected output '{0}' in model '{1}'\n{2}".format(k, onnx, msg))
            tested += 1
    elif isinstance(expected, numpy.ndarray):
        if isinstance(output, list):
            if expected.shape[0] == len(output) and isinstance(output[0], dict):
                import pandas
                output = pandas.DataFrame(output)
                output = output[list(sorted(output.columns))]
                output = output.values
        if isinstance(output, (dict, list)):
            if len(output) != 1:
                ex = str(output)
                if len(ex) > 70:
                    ex = ex[:70] + "..."
                raise OnnxRuntimeAssertionError("More than one output when 1 is expected for onnx '{0}'\n{1}".format(onnx, ex))
            output = output[-1]
        if not isinstance(output, numpy.ndarray):
            raise OnnxRuntimeAssertionError("output must be an array for onnx '{0}' not {1}".format(onnx, type(output)))
        if onnx_shape is not None:
            if len(onnx_shape) == 2:
                cols = onnx_shape[1]
                ecols = output.shape[1] if len(output.shape) == 2 else 1
                if cols != ecols:
                    raise OnnxRuntimeAssertionError("Unexpected onnx shape {0} != {1} for onnx '{2}'".format(
                                onnx_shape, output.shape, onnx))
        msg = compare_outputs(expected, output, decimal=decimal, **kwargs)
        if isinstance(msg, ExpectedAssertionError):
            raise msg
        if msg:
            raise OnnxRuntimeAssertionError("Unexpected output in model '{0}'\n{1}".format(onnx, msg))
        tested += 1
    else:
        from scipy.sparse.csr import csr_matrix
        if isinstance(expected, csr_matrix):
            # DictVectorizer
            one_array = numpy.array(output)
            msg = compare_outputs(expected.todense(), one_array, decimal=decimal, **kwargs)
            if msg:
                raise OnnxRuntimeAssertionError("Unexpected output in model '{0}'\n{1}".format(onnx, msg))
            tested += 1
        else:
            raise OnnxRuntimeAssertionError("Unexpected type for expected output ({1}) and onnx '{0}'".format(onnx, type(expected)))
    if tested ==0:
        raise OnnxRuntimeAssertionError("No test for onnx '{0}'".format(onnx))
298052
def percent_rank(expr, sort=None, ascending=True):
    
    return _rank_op(expr, PercentRank, types.float64, sort=sort, ascending=ascending)
524097
def _calc_input_estimates(keyvals, get_retriever):
    
    out = {}
    for key, val in keyvals.items():
        size = _calc_file_size(val, 0, get_retriever)
        if size:
            out[key] = size
    return out
1042972
def get(self):
        """"""
        ret = sparklines(self.percents)[0]
        if self.__with_text:
            percents_without_none = [x for x in self.percents if x is not None]
            if len(percents_without_none) > 0:
                ret = '{}{:5.1f}%'.format(ret, percents_without_none[-1])
        return nativestr(ret)
995243
def stash_split(fqdn, result, *argl, **argd):
    
    global _splits
    if fqdn == "sklearn.cross_validation.train_test_split":
        key = id(result[1])
        _splits[key] = result

    #We don't actually want to return anything for the analysis; we are using it
    #as a hook to save pointers to the dataset split so that we can easily
    #analyze performance later on.
    return None
416710
def percentile(arr, percent):
    
    arr = sorted(arr)
    index = (len(arr) - 1) * percent
    floor = math.floor(index)
    ceil = math.ceil(index)
    if floor == ceil:
        return arr[int(index)]
    low_value = arr[int(floor)] * (ceil - index)
    high_value = arr[int(ceil)] * (index - floor)
    return low_value + high_value
1037103
def get_best_match(text_log_error):
    
    score_cut_off = 0.7
    return (text_log_error.matches.filter(score__gt=score_cut_off)
                                  .order_by("-score", "-classified_failure_id")
                                  .select_related('classified_failure')
                                  .first())
1271042
def get_output(self, assessment, options):
        
        responseFormat=None
        if options and 'format' in options and options['format'] is not None:
            responseFormat = options['format']
            options['format'] = None

        url = '/assessment/' + str(assessment) + '/output'

        if 'offset' in options:
            url += '?offset=' + str(options['offset'])

        response = self.http.downstream(url, responseFormat)
        stream = sseclient.SSEClient(response)
        return stream
343710
def __process_results(results):
    
    if 'no match' in results and 'returning 0 elements' in results:
        return []

    result_list = []

    # Splts the result and cuts first and last dataset which are comments
    split = results.split(sep='\n\n')[1:-1]

    for entry in split:
        entry_dict = {}
        for value in entry.split('\n'):
            if len(value) < 1:
                continue
            (desc, val) = value.split(': ')
            entry_dict[desc.replace('-', '')] = val.strip(' ')
        result_list.append(entry_dict)
    return result_list
850806
def score(self, X, y):
        
        predictions = self.predict(X)
        true = 0.0
        total = 0.0
        for i in range(len(predictions)):
            total += 1
            if predictions[i] == y[i]:
                true += 1
        return true/total