本文整理汇总了Python中statistics.mode方法的典型用法代码示例。如果您正苦于以下问题:Python statistics.mode方法的具体用法?Python statistics.mode怎么用?Python statistics.mode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类statistics
的用法示例。
在下文中一共展示了statistics.mode方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: predictEnsemble
# 需要导入模块: import statistics [as 别名]
# 或者: from statistics import mode [as 别名]
def predictEnsemble(self, models, testSamples):
uniqueLabels = np.unique(testSamples["Labels"])
pred_labels = []
final_labels = [None for _ in range(testSamples["Samples"])]
for i, model in enumerate(models):
correct, labels = self.predict(model, testSamples)
pred_labels.append(labels)
for i in range(testSamples["Samples"]):
ensemble_labels = [pred_labels[j][i] for j in range(len(pred_labels))]
try:
final_labels[i] = mode(ensemble_labels)
except: #Guess if there is no favorite
final_labels[i] = random.choice(uniqueLabels)
final_correct = sum([final_labels[i] == testSamples[i].label for i in range(testSamples["Samples"])])
return final_correct, final_labels
示例2: mode
# 需要导入模块: import statistics [as 别名]
# 或者: from statistics import mode [as 别名]
def mode(input_list): # Defining function "mode."
"""This function returns the mode(Mode as in the measures of
central tendency) of the input data.
The input list may contain any Datastructure or any Datatype.
>>> input_list = [2, 3, 4, 5, 3, 4, 2, 5, 2, 2, 4, 2, 2, 2]
>>> mode(input_list)
2
>>> input_list = [2, 3, 4, 5, 3, 4, 2, 5, 2, 2, 4, 2, 2, 2]
>>> mode(input_list) == statistics.mode(input_list)
True
"""
# Copying input_list to check with the index number later.
check_list = input_list.copy()
result = list() # Empty list to store the counts of elements in input_list
for x in input_list:
result.append(input_list.count(x))
input_list.remove(x)
y = max(result) # Gets the maximum value in the result list.
# Returns the value with the maximum number of repetitions.
return check_list[result.index(y)]
示例3: confidence
# 需要导入模块: import statistics [as 别名]
# 或者: from statistics import mode [as 别名]
def confidence(self, features):
""" Calculate the confidence of the result
:param features:
:return: confidence
"""
votes = []
for c in self._classifiers:
v = c.classify(features)
votes.append(v)
total_of_winner_votes = votes.count(mode(votes))
conf = total_of_winner_votes / len(votes)
return conf
# Fetching word features
示例4: append_data_statistics
# 需要导入模块: import statistics [as 别名]
# 或者: from statistics import mode [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
示例5: classify
# 需要导入模块: import statistics [as 别名]
# 或者: from statistics import mode [as 别名]
def classify(self, features):
votes = []
for c in self._classifiers:
v = c.classify(features)
votes.append(v)
return mode(votes)
示例6: confidence
# 需要导入模块: import statistics [as 别名]
# 或者: from statistics import mode [as 别名]
def confidence(self, features):
votes = []
for c in self._classifiers:
v = c.classify(features)
votes.append(v)
choice_votes = votes.count(mode(votes))
conf = choice_votes/len(votes)
return conf
示例7: mode
# 需要导入模块: import statistics [as 别名]
# 或者: from statistics import mode [as 别名]
def mode(self):
return statistics.mode(self.price)
# 波动率
# 振幅
示例8: mode
# 需要导入模块: import statistics [as 别名]
# 或者: from statistics import mode [as 别名]
def mode(self):
'返回DataStruct.price的众数'
try:
res = self.price.groupby(level=1
).apply(lambda x: statistics.mode(x))
res.name = 'mode'
return res
except:
return None
# 振幅
示例9: get_neighbourhood
# 需要导入模块: import statistics [as 别名]
# 或者: from statistics import mode [as 别名]
def get_neighbourhood(self,X_train, y_train, point, K):
pairs = zip(X_train, y_train)
pairs.sort(key = lambda pair: self.euclidean_distance(point, pair[0]))
pairs = pairs[0:K]
return mode(zip(*pairs)[1])
示例10: prepare_data
# 需要导入模块: import statistics [as 别名]
# 或者: from statistics import mode [as 别名]
def prepare_data(self):
"""Overload method from UnivariateCommonMixin."""
# Make sure test data has exactly one mode.
return [1, 1, 1, 1, 3, 4, 7, 9, 0, 8, 2]