当前位置: 首页>>代码示例>>Python>>正文


Python statistics.harmonic_mean方法代码示例

本文整理汇总了Python中statistics.harmonic_mean方法的典型用法代码示例。如果您正苦于以下问题:Python statistics.harmonic_mean方法的具体用法?Python statistics.harmonic_mean怎么用?Python statistics.harmonic_mean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在statistics的用法示例。


在下文中一共展示了statistics.harmonic_mean方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: mean_harmonic

# 需要导入模块: import statistics [as 别名]
# 或者: from statistics import harmonic_mean [as 别名]
def mean_harmonic(self):
        return statistics.harmonic_mean(self.price)

    # 众数 
开发者ID:QUANTAXIS,项目名称:QUANTAXIS,代码行数:6,代码来源:QAAnalysis_dataframe.py

示例2: mean_harmonic

# 需要导入模块: import statistics [as 别名]
# 或者: from statistics import harmonic_mean [as 别名]
def mean_harmonic(self):
        '返回DataStruct.price的调和平均数'
        res = self.price.groupby(level=1
                                 ).apply(lambda x: statistics.harmonic_mean(x))
        res.name = 'mean_harmonic'
        return res

    # 众数 
开发者ID:QUANTAXIS,项目名称:QUANTAXIS,代码行数:10,代码来源:base_datastruct.py

示例3: f1_score

# 需要导入模块: import statistics [as 别名]
# 或者: from statistics import harmonic_mean [as 别名]
def f1_score(ground_truth, signal, k):
  """Computes the f1 score for the top k words between frequency dicts.

  Args:
    ground_truth: The ground truth dict.
    signal: The obtained heavy hitters dict.
    k: The number of top items that are consider heavy hitters.

  Returns:
    F1 score of the signal in detecting a top k item.
  """
  prec = precision(ground_truth, signal, k)
  rec = recall(ground_truth, signal, k)
  return statistics.harmonic_mean([prec, rec]) 
开发者ID:tensorflow,项目名称:federated,代码行数:16,代码来源:heavy_hitters_utils.py

示例4: HARMONIC_MEAN

# 需要导入模块: import statistics [as 别名]
# 或者: from statistics import harmonic_mean [as 别名]
def HARMONIC_MEAN(df, n, price='Close'):
    """
    Harmonic mean of data
    Returns: list of floats = jhta.HARMONIC_MEAN(df, n, price='Close')
    """
    harmonic_mean_list = []
    if n == len(df[price]):
        start = None
        for i in range(len(df[price])):
            if df[price][i] != df[price][i]:
                harmonic_mean = float('NaN')
            else:
                if start is None:
                    start = i
                end = i + 1
                harmonic_mean = statistics.harmonic_mean(df[price][start:end])
            harmonic_mean_list.append(harmonic_mean)
    else:
        for i in range(len(df[price])):
            if i + 1 < n:
                harmonic_mean = float('NaN')
            else:
                start = i + 1 - n
                end = i + 1
                harmonic_mean = statistics.harmonic_mean(df[price][start:end])
            harmonic_mean_list.append(harmonic_mean)
    return harmonic_mean_list 
开发者ID:joosthoeks,项目名称:jhTAlib,代码行数:29,代码来源:statistic_functions.py

示例5: compute_metrics

# 需要导入模块: import statistics [as 别名]
# 或者: from statistics import harmonic_mean [as 别名]
def compute_metrics(qids_to_relevant_passageids, qids_to_ranked_candidate_passages,MaxMRRRank = 10):
    """Compute MRR metric
    Args:    
    p_qids_to_relevant_passageids (dict): dictionary of query-passage mapping
        Dict as read in with load_reference or load_reference_from_stream
    p_qids_to_ranked_candidate_passages (dict): dictionary of query-passage candidates
    Returns:
        dict: dictionary of metrics {'MRR': <MRR Score>}
    """
    all_scores = {}
    MRR = 0
    qids_with_relevant_passages = 0
    ranking = []
    for qid in qids_to_ranked_candidate_passages:
        if qid in qids_to_relevant_passageids:
            ranking.append(0)
            target_pid = qids_to_relevant_passageids[qid]
            candidate_pid = qids_to_ranked_candidate_passages[qid]
            for i in range(0,MaxMRRRank):
                if candidate_pid[i] in target_pid:
                    MRR += 1/(i + 1)
                    ranking.pop()
                    ranking.append(i+1)
                    break

    if len(ranking) == 0:
        raise IOError("No matching QIDs found. Are you sure you are scoring the evaluation set?")
    
    MRR = MRR/len(ranking)
    all_scores['MRR'] = MRR
    all_scores['QueriesRanked'] = len(ranking)
    all_scores['QueriesWithNoRelevant'] = sum((1 for x in ranking if x == 0))
    all_scores['QueriesWithRelevant'] = sum((1 for x in ranking if x > 0))

    all_scores['AverageRankGoldLabel@'+str(MaxMRRRank)] = statistics.mean((x for x in ranking if x > 0))
    all_scores['MedianRankGoldLabel@'+str(MaxMRRRank)] = statistics.median((x for x in ranking if x > 0))

    all_scores['AverageRankGoldLabel'] = statistics.mean(ranking)
    all_scores['MedianRankGoldLabel'] = statistics.median(ranking)
    all_scores['HarmonicMeanRankingGoldLabel'] = statistics.harmonic_mean(ranking)
    return all_scores 
开发者ID:sebastian-hofstaetter,项目名称:sigir19-neural-ir,代码行数:43,代码来源:msmarco_eval.py

示例6: harmonic_mean

# 需要导入模块: import statistics [as 别名]
# 或者: from statistics import harmonic_mean [as 别名]
def harmonic_mean(args):
    if "harmonic_mean" not in dir(statistics):
        return builtins.len(args) / sum([1 / x for x in args])
    return statistics.harmonic_mean(args) 
开发者ID:TuringApp,项目名称:Turing,代码行数:6,代码来源:stats.py

示例7: time_testcase_statistics

# 需要导入模块: import statistics [as 别名]
# 或者: from statistics import harmonic_mean [as 别名]
def time_testcase_statistics(
    testcase: typing.Callable,
    *args: typing.Any,
    runs: int = 10,
    sleep: float = 0,
    **kwargs: typing.Any,
) -> None:
    """
    Take multiple measurements about the run-time of a testcase and return/display statistics.

    :param testcase: Testcase to call.
    :param args,\\ kwargs: Arguments to pass to the testcase.
    :param int runs: How many samples to take.
    :param float sleep: How much time to sleep in between the runs.  Example
        use:  Maybe the board does not discharge quick enough so it can cause
        troubles when the subsecuent testcase run tries to boot again the board
    """

    elapsed_times = []

    for n in range(runs):
        elapsed_time, _ = time_testcase(testcase, *args, **kwargs)
        elapsed_times.append(elapsed_time)
        time.sleep(sleep)

    results = TimingResults(
        statistics.mean(elapsed_times),
        statistics.harmonic_mean(elapsed_times),
        statistics.median(elapsed_times),
        statistics.pvariance(elapsed_times),
        statistics.pstdev(elapsed_times),
    )

    tbot.log.message(
        f"""\
    Timing Results:
        {tbot.log.c('mean').green}: {results.mean}
        {tbot.log.c('harmonic mean').green}: {results.harmonic_mean}
        {tbot.log.c('median').green}: {results.median}
        {tbot.log.c('variance').green}: {results.pvariance}
        {tbot.log.c('standard deviation').green}: {results.pstdev}
    """
    ) 
开发者ID:Rahix,项目名称:tbot,代码行数:45,代码来源:__init__.py


注:本文中的statistics.harmonic_mean方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。