當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。