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


Python statistics.mode方法代码示例

本文整理汇总了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 
开发者ID:sharford5,项目名称:SFA_Python,代码行数:19,代码来源:ShotgunEnsembleClassifier.py

示例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)] 
开发者ID:TheAlgorithms,项目名称:Python,代码行数:24,代码来源:average_mode.py

示例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 
开发者ID:singnet,项目名称:nlp-services,代码行数:19,代码来源:analyze_mod.py

示例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 
开发者ID:mozilla,项目名称:TTS,代码行数:27,代码来源:analyze.py

示例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) 
开发者ID:abhi007tyagi,项目名称:JARVIS,代码行数:8,代码来源:jarvis.py

示例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 
开发者ID:abhi007tyagi,项目名称:JARVIS,代码行数:11,代码来源:jarvis.py

示例7: mode

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

    # 波动率

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

示例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

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

示例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]) 
开发者ID:ggulgun,项目名称:NIDS-Intrusion-Detection,代码行数:7,代码来源:knn.py

示例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] 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:6,代码来源:test_statistics.py


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