本文整理汇总了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