本文整理匯總了Python中statistics.StatisticsError方法的典型用法代碼示例。如果您正苦於以下問題:Python statistics.StatisticsError方法的具體用法?Python statistics.StatisticsError怎麽用?Python statistics.StatisticsError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類statistics
的用法示例。
在下文中一共展示了statistics.StatisticsError方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: diagnosticity
# 需要導入模塊: import statistics [as 別名]
# 或者: from statistics import StatisticsError [as 別名]
def diagnosticity(evaluations):
"""Return the diagnosticity of a piece of evidence given its evaluations against a set of hypotheses.
:param evaluations: an iterable of iterables of Eval for a piece of evidence
"""
# The "diagnosticity" needs to capture how well the evidence separates/distinguishes the hypotheses. If we don't
# show a preference between consistent/inconsistent, STDDEV captures this intuition OK. However, in the future,
# we may want to favor evidence for which hypotheses are inconsistent. Additionally, we may want to calculate
# "marginal diagnosticity" which takes into the rest of the evidence.
# (1) calculate the consensus for each hypothesis
# (2) map N/A to neutral because N/A doesn't help determine consistency of the evidence
# (3) calculate the population standard deviation of the evidence. It's more reasonable to consider the set of
# hypotheses at a given time to be the population of hypotheses than as a "sample" (although it doesn't matter
# much because we're comparing across hypothesis sets of the same size)
na_neutral = map(mean_na_neutral_vote, evaluations) # pylint: disable=bad-builtin
try:
return statistics.pstdev(filter(None.__ne__, na_neutral)) # pylint: disable=bad-builtin
except statistics.StatisticsError:
return 0.0
示例2: _get_center_coords
# 需要導入模塊: import statistics [as 別名]
# 或者: from statistics import StatisticsError [as 別名]
def _get_center_coords(
locations: Iterable[Tuple[float, float]], mode: str = "median"
) -> Tuple[float, float]:
"""Return the center (median) of the coordinates."""
if not locations:
return 0, 0
locs = list(locations)
if mode == "median":
try:
return (
stats.median([loc[0] for loc in locs if not math.isnan(loc[0])]),
stats.median([loc[1] for loc in locs if not math.isnan(loc[1])]),
)
except stats.StatisticsError:
pass
return (
stats.mean([loc[0] for loc in locs if not math.isnan(loc[0])]),
stats.mean([loc[1] for loc in locs if not math.isnan(loc[1])]),
)
示例3: mode
# 需要導入模塊: import statistics [as 別名]
# 或者: from statistics import StatisticsError [as 別名]
def mode(data):
"""Return the mode, the most common data point from discrete or nominal data.
If there are multiple modes with the same frequency, the first one encountered
in data is returned.
If data is empty, StatisticsError is raised.
To speed up the computation, the bit length of the sample range max(data) - min(data)
is revealed, provided this range is not too small.
"""
if iter(data) is data:
x = list(data)
else:
x = data[:]
n = len(x)
if not n:
raise statistics.StatisticsError('mode requires at least one data point')
if isinstance(x[0], sectypes.SecureObject):
return _mode(x, PRIV=runtime.options.sec_param//6)
return statistics.mode(x) # NB: raises StatisticsError in Python < 3.8 if x is multimodal
示例4: append_data_statistics
# 需要導入模塊: import statistics [as 別名]
# 或者: from statistics import StatisticsError [as 別名]
def append_data_statistics(meta_data):
# get data statistics
for char_cnt in meta_data:
data = meta_data[char_cnt]["data"]
audio_len_list = [d["audio_len"] for d in data]
mean_audio_len = mean(audio_len_list)
try:
mode_audio_list = [round(d["audio_len"], 2) for d in data]
mode_audio_len = mode(mode_audio_list)
except StatisticsError:
mode_audio_len = audio_len_list[0]
median_audio_len = median(audio_len_list)
try:
std = stdev(
d["audio_len"] for d in data
)
except StatisticsError:
std = 0
meta_data[char_cnt]["mean"] = mean_audio_len
meta_data[char_cnt]["median"] = median_audio_len
meta_data[char_cnt]["mode"] = mode_audio_len
meta_data[char_cnt]["std"] = std
return meta_data