How to use the statistics.mean function in statistics

To help you get started, we’ve selected a few statistics examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github creativecommons / cccatalog / src / cc_catalog_airflow / dags / util / popularity / test_math.py View on Github external
def test_gen_tsv():
    output_tsv = io.StringIO()
    percentiles = {'views': 60, 'global_usage_count': 10}
    pop_fields = ['views', 'global_usage_count']
    with open(os.path.join(RESOURCES, 'mock_popularity_dump.tsv'), 'r') as tsv:
        generate_popularity_tsv(tsv, output_tsv, percentiles, pop_fields)
        output_tsv.seek(0)
    scores = _parse_normalized_tsv(output_tsv)

    # Scores should be floats ranging from 0 to 100.
    for _, score in scores.items():
        assert 0 < score < 100
    # The score of the third row should be the average of the first and second
    assert statistics.mean([scores[0], scores[1]]) == scores[2]
github SivilTaram / FollowUp / eval.py View on Github external
all_bleu_scores = []
        all_sym_acc = []

        for predict_example, test_example, test_sym in iter_eval:
            predict_example = predict_example.strip()
            test_example = test_example.strip().split('\t')[-2]
            test_sym = test_sym.strip().split(' ')
            # check bleu
            bleu_score = evaluate_bleu_score(predict_example, test_example)
            sym_acc = evaluate_sym_acc(predict_example, test_sym, test_example)

            all_bleu_scores.append(bleu_score)
            all_sym_acc.append(sym_acc)

        avg_bleu_score = 100 * statistics.mean(all_bleu_scores)
        avg_sym_acc = 100 * statistics.mean(all_sym_acc)

        print("=" * 80)
        print(" " * 20 + " FollowUp Dataset Evaluation Result")
        print("=" * 80)
        print("BLEU Score:  {:.2f} (%)".format(avg_bleu_score))
        print("Symbol Acc:  {:.2f} (%)".format(avg_sym_acc))
github chiphuyen / lazynlp / lazynlp / analytics.py View on Github external
line_token_lengths = [len(token) for token in tokens]
            token_lengths.append([len(tokens),
                                  sum(line_token_lengths) / len(tokens)])
            line = f.readline()

    total_tokens = sum([pair[0] for pair in token_lengths])
    total_chars = sum([pair[0] * pair[1] for pair in token_lengths])
    average_chars = total_chars / total_tokens
    print(f'Character per word: average = {average_chars}.')
    print(f'Word count per line:'
          f'\n\taverage = {statistics.mean(line_lengths)},'
          f'\n\tmedian = {statistics.median(line_lengths)},'
          f'\n\tmax = {max(line_lengths)},'
          f'\n\tmin = {min(line_lengths)},'
          f'\n\tstddev = {statistics.stdev(line_lengths)}.')
    return statistics.mean(line_lengths), average_chars
github sglebs / srccheck / utilities / srcdiffplot.py View on Github external
def add_stats(all_before, all_after, entity_names, colors):
    avg_before = statistics.mean(all_before)
    avg_after = statistics.mean(all_after)
    all_before.append(avg_before)
    all_after.append(avg_after)
    entity_names.append("(AVG)")
    colors.append("b")
    median_before = statistics.median(all_before)
    median_after = statistics.median(all_after)
    all_before.append(median_before)
    all_after.append(median_after)
    entity_names.append("(MEDIAN)")
    colors.append("y")
    stdev_before = statistics.pstdev(all_before,avg_before)
    stdev_after = statistics.pstdev(all_after,avg_after)
    all_before.append(stdev_before)
    all_after.append(stdev_after)
    entity_names.append("(STDEV)")
github spacetelescope / jwql / jwql / instrument_monitors / nirspec_monitors / data_trending / dt_cron_job.py View on Github external
----------
    conn : DBobject
        Connection object to temporary database
    path : str
        defines path to the files
    '''

    #process raw data with once a day routine
    return_data, lamp_data = whole_day_routine(m_raw_data)
    FW, GWX, GWY = wheelpos_routine(m_raw_data)

    #put all data to a database that uses a condition
    for key, value in return_data.items():
        m = m_raw_data.mnemonic(key)
        length = len(value)
        mean = statistics.mean(value)
        deviation = statistics.stdev(value)
        dataset = (float(m.meta['start']), float(m.meta['end']), length, mean, deviation)
        sql.add_data(conn, key, dataset)


    #add rest of the data to database -> no conditions applied
    for identifier in mn.mnemSet_day:
        m = m_raw_data.mnemonic(identifier)
        temp = []
        #look for all values that fit to the given conditions
        for element in m:
            temp.append(float(element['value']))
        #return None if no applicable data was found
        if len(temp) > 2:
            length = len(temp)
            mean = statistics.mean(temp)
github ppaanngggg / ParadoxTrading / ParadoxTrading / Indicator / General / AdaBBands.py View on Github external
def _addOne(self, _data_struct: DataStruct):
        index_value = _data_struct.index()[0]
        self.buf.append(_data_struct.getColumn(self.use_key)[0])

        if len(self.data) > self.period:
            const_std = statistics.pstdev(self.buf[-self.period:])
            self.dynamic_n *= const_std / self.prev_std
            self.dynamic_n = max(self.min_n, self.dynamic_n)
            self.dynamic_n = min(self.max_n, self.dynamic_n)
            tmp_n = int(round(self.dynamic_n))

            mean = statistics.mean(self.buf[-tmp_n:])
            std = statistics.pstdev(self.buf[-tmp_n:])

            self.data.addRow(
                [index_value, mean + self.rate * std,
                 mean, mean - self.rate * std],
                self.keys
            )

            self.prev_std = const_std
        else:
            if len(self.data) == self.period:
                self.prev_std = statistics.pstdev(self.buf)

            self.data.addRow(
                [index_value, None, None, None],
                self.keys
github SUNCAT-Center / CatalysisHubBackend / apps / catKitDemo / __init__.py View on Github external
if isinstance(request.args.get('bulkParams', '{}'), str):
        bulk_params = json.loads(request.args.get('bulkParams', '{}'))
    else:
        bulk_params = request.args.get('bulkParams', {})

    cubic = bulk_params.get(
        'cubic', 'true').lower() == 'true'
    structure = bulk_params.get('structure', 'fcc')
    lattice_constant = float(bulk_params.get('lattice_constant', 4.0))

    elements = bulk_params.get('elements', ['Pt'])
    input_format = str(bulk_params.get('format', 'cif') or 'cif')

    if elements:
        lattice_constant = statistics.mean(
            atomic_radii[x] for x in elements) * (2 * math.sqrt(2) / 100.)

    for i in range(1, 5):
        try:
            atoms = ase.build.bulk(
                ''.join(
                    elements[
                        :i]),
                structure,
                a=lattice_constant,
                cubic=cubic)
            break
        except Exception as e:
            print(e)
            pass
    for i, atom in enumerate(atoms):
github broadinstitute / single_cell_portal / scripts / ideogram / matrix_to_ideogram_annots.py View on Github external
gene_exp_list = gene_expression_lists[gene]

            scores_list = [gene]

            cluster = cluster_group[scope][cluster_name]
            for cluster_label in cluster:
                # cell_annot = cluster[name]
                cell_annot_expressions = []
                for cell in cluster[cluster_label]:
                    if cell not in cells: continue
                    index_of_cell_in_matrix = cells[cell] - 1
                    gene_exp_in_cell = gene_exp_list[index_of_cell_in_matrix]
                    cell_annot_expressions.append(gene_exp_in_cell)
                if len(cell_annot_expressions) == 0: continue
                mean_cluster_expression = round(mean(cell_annot_expressions), 3)
                scores_list.append(mean_cluster_expression)

            if i % 1000 == 0 and i != 0:
                print(
                    'Processed ' + str(i) + ' of ' + str(len(gene_expression_lists)) + ' ' + 
                    'for ' + scope + ', cluster ' + cluster_name
                )

            scores_lists.append(scores_list)

        scores_lists.reverse()
        return scores_lists
github FederatedAI / FATE-Cloud / fate_manager / service / monitor_service.py View on Github external
def get_job_metrics(job_day_list):
    # max, min, mean
    job_elapsed_list = [job_day.job_elapsed for job_day in job_day_list]
    if job_elapsed_list:
        return max(job_elapsed_list), min(job_elapsed_list), mean(job_elapsed_list)
    else:
        return 0, 0, 0
github t2y / python-study / SearchString / boyer_moore_horspool.py View on Github external
with args.data() as blob:
        table = make_table(byte_word)
        results = boyer_moore_horspool_search(blob, byte_word, table)

    for result in results:
        log.debug(result.decode('utf-8').strip())
    log.info('検索結果: %d 件' % len(results))


if __name__ == '__main__':
    args = parse_argument()
    if args.measure:
        setup = 'from __main__ import main'
        sec = timeit.repeat('main()', setup=setup, repeat=3, number=5)
        log.setLevel(logging.INFO)
        log.info('平均実行時間: %f sec' % statistics.mean(sec))
    else:
        main()