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


Python stats.mode方法代码示例

本文整理汇总了Python中scipy.stats.mode方法的典型用法代码示例。如果您正苦于以下问题:Python stats.mode方法的具体用法?Python stats.mode怎么用?Python stats.mode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scipy.stats的用法示例。


在下文中一共展示了stats.mode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: point_add_sem_label

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import mode [as 别名]
def point_add_sem_label(pt, sem, k=10):
    sem_pt = sem[:, 0:3]
    sem_label = sem[:,3]
    pt_label = np.zeros(pt.shape[0])
    if pt.shape[0]==0:
        return pt_label
    else:
        nbrs = NearestNeighbors(n_neighbors=k,algorithm='ball_tree').fit(sem_pt)
        distances, indices = nbrs.kneighbors(pt)
        for i in range(pt.shape[0]):
            labels = sem_label[indices[i]]
            l, count = stats.mode(labels, axis=None)
            pt_label[i] = l
        return pt_label


    
# ----------------------------------------
# Testing
# ---------------------------------------- 
开发者ID:zaiweizhang,项目名称:H3DNet,代码行数:22,代码来源:pc_util.py

示例2: transform

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import mode [as 别名]
def transform(self, X):
        """ transform
        
        Does the transformation process in the samples in X.
        
        Parameters
        ----------
        X: numpy.ndarray of shape (n_samples, n_features)
            The sample or set of samples that should be transformed.
        
        """
        r, c = get_dimensions(X)
        for i in range(r):
            if self.strategy in ['mean', 'median', 'mode']:
                self.window.add_element([X[i][:]])
            for j in range(c):
                if X[i][j] in self.missing_value or np.isnan(X[i][j]):
                    X[i][j] = self._get_substitute(j)

        return X 
开发者ID:scikit-multiflow,项目名称:scikit-multiflow,代码行数:22,代码来源:missing_values_cleaner.py

示例3: partial_fit

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import mode [as 别名]
def partial_fit(self, X, y=None):
        """ partial_fit
        
        Partial fits the model.
        
        Parameters
        ----------
        X: numpy.ndarray of shape (n_samples, n_features)
            The sample or set of samples that should be transformed.
            
        y: Array-like
            The true labels.
        
        Returns
        -------
        MissingValuesCleaner
            self
        
        """
        X = np.asarray(X)
        if self.strategy in ['mean', 'median', 'mode']:
            self.window.add_element(X)
        return self 
开发者ID:scikit-multiflow,项目名称:scikit-multiflow,代码行数:25,代码来源:missing_values_cleaner.py

示例4: _get_redop

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import mode [as 别名]
def _get_redop(red_op, weights=None, axis=None):
    if red_op in ['mean', 'average']:
        if weights is None:
            def fred(x, w): return np.mean(x, axis=axis)
        else:
            def fred(x, w): return np.average(x, weights=w, axis=axis)
    elif red_op == 'median':
        def fred(x, w): return np.median(x, axis=axis)
    elif red_op == 'mode':
        if weights is None:
            def fred(x, w): return mode(x, axis=axis)[0].ravel()
        else:
            def fred(x, w): return weighted_mode(x, w, axis=axis)
    elif red_op == 'sum':
        def fred(x, w): return np.sum(x if w is None else w * x, axis=axis)
    elif red_op == 'max':
        def fred(x, w): return np.max(x, axis=axis)
    elif red_op == 'min':
        def fred(x, w): return np.min(x, axis=axis)
    else:
        raise ValueError("Unknown reduction operation '{0}'".format(red_op))
    return fred 
开发者ID:MICA-MNI,项目名称:BrainSpace,代码行数:24,代码来源:parcellation.py

示例5: test

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import mode [as 别名]
def test(self, test_data, test_target):
        t = 0
        # TODO: refactor the RF test function to depend not on an external
        # root but on itself
        dt = FastDecisionTree(1, 1)
        yhat_forest = np.zeros((test_data.shape[0], self.n_trees))
        for i in range(len(self.roots)):
            r = self.roots[i]
            prog_bar(t, self.n_trees)
            t += 1

            yhat_forest[:, i:] = dt.test_preds(r, test_data)

        prog_bar(self.n_trees, self.n_trees)

        yhat = stats.mode(yhat_forest, axis=1)[0]
        return yhat 
开发者ID:bdol,项目名称:bdol-ml,代码行数:19,代码来源:random_forest.py

示例6: testForest

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import mode [as 别名]
def testForest(roots, X, Y):
  errs = 0.0

  for i in range(0, X.shape[0]):
    votes = []
    for r in roots:
      yhat = np.argmax(dt_value(r, X[i, :]))
      votes.append(yhat)
    yhatEnsemble = stats.mode(votes)
    if Y[i, int(yhatEnsemble[0])] != 1:
      errs += 1.0

  return errs/X.shape[0]

# Turn off runtime warnings for invalid or divide errors
# These arise when calculating the entropy. We set any invalid entropy
# calculations (e.g. log(0)) to 0. 
开发者ID:bdol,项目名称:bdol-ml,代码行数:19,代码来源:random_forests.py

示例7: test_random_weights

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import mode [as 别名]
def test_random_weights():
    # set this up so that each row should have a weighted mode of 6,
    # with a score that is easily reproduced
    mode_result = 6

    rng = np.random.RandomState(0)
    x = rng.randint(mode_result, size=(100, 10))
    w = rng.random_sample(x.shape)

    x[:, :5] = mode_result
    w[:, :5] += 1

    mode, score = weighted_mode(x, w, axis=1)

    assert_array_equal(mode, mode_result)
    assert_array_almost_equal(score.ravel(), w[:, :5].sum(1)) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:18,代码来源:test_extmath.py

示例8: find_key

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import mode [as 别名]
def find_key(streamciphers, iterations=50):

    ciphers = deepcopy(streamciphers)
    n = len(ciphers)
    # key size of longest cipher
    ksize = len(max(ciphers, key=len))
    possiblekeys = []

    for _ in range(iterations):

        shuffle(ciphers)
        k = bytearray(ksize)

        for a in range(n - 2):
            for b in range(a + 1, n - 1):
                for c in range(b + 1, n):
                    x, y, z = truncate3(ciphers[a], ciphers[b], ciphers[c])
                    build_key(k, x, y, z)

        possiblekeys.append(k)

    # finalize key using frequency analysis
    key_array = stats.mode(numpy.array(possiblekeys))[0][0]
    return bytes(list(key_array)) 
开发者ID:mithi,项目名称:simple-cryptography,代码行数:26,代码来源:manytimepad.py

示例9: test_axes

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import mode [as 别名]
def test_axes(self):
        data1 = [10, 10, 30, 40]
        data2 = [10, 10, 10, 10]
        data3 = [20, 10, 20, 20]
        data4 = [30, 30, 30, 30]
        data5 = [40, 30, 30, 30]
        arr = np.array([data1, data2, data3, data4, data5])

        vals = stats.mode(arr, axis=None)
        assert_equal(vals[0], np.array([30]))
        assert_equal(vals[1], np.array([8]))

        vals = stats.mode(arr, axis=0)
        assert_equal(vals[0], np.array([[10, 10, 30, 30]]))
        assert_equal(vals[1], np.array([[2, 3, 3, 2]]))

        vals = stats.mode(arr, axis=1)
        assert_equal(vals[0], np.array([[10], [10], [20], [30], [30]]))
        assert_equal(vals[1], np.array([[2], [4], [3], [4], [3]])) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:21,代码来源:test_stats.py

示例10: predict

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import mode [as 别名]
def predict(record):
    ecg = load.load_ecg(record +".mat")
    preproc = util.load(".")
    x = preproc.process_x([ecg])

    params = json.load(open("config.json"))
    params.update({
        "compile" : False,
        "input_shape": [None, 1],
        "num_categories": len(preproc.classes)
    })

    model = network.build_network(**params)
    model.load_weights('model.hdf5')

    probs = model.predict(x)
    prediction = sst.mode(np.argmax(probs, axis=2).squeeze())[0][0]
    return preproc.int_to_class[prediction] 
开发者ID:awni,项目名称:ecg,代码行数:20,代码来源:evaler.py

示例11: main

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import mode [as 别名]
def main():
    repeat = 10
    num_point = 500
    model.eval()
    torch.set_grad_enabled(False)

    # load pc(should be in local gripper coordinate)
    # local_pc: (N, 3)
    # local_pc = np.load("test.npy")
    local_pc = np.random.random([500, 3])  # test only
    predict = []
    for _ in range(repeat):
        if len(local_pc) >= num_point:
            local_pc = local_pc[np.random.choice(len(local_pc), num_point, replace=False)]
        else:
            local_pc = local_pc[np.random.choice(len(local_pc), num_point, replace=True)]

        # run model
        predict.append(test_network(model, local_pc)[0])
    print("voting: ", predict)
    predict = mode(predict).mode[0]

    # output
    print("Test result:", predict) 
开发者ID:lianghongzhuo,项目名称:PointNetGPD,代码行数:26,代码来源:main_test.py

示例12: resample_eICU_patient

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import mode [as 别名]
def resample_eICU_patient(pid, resample_factor_in_min, variables, upto_in_minutes):
    """
    Resample a *single* patient.
    """
    pat_df = pd.read_hdf(paths.eICU_hdf_dir + '/vitalPeriodic.h5',
                         where='patientunitstayid = ' + str(pid),
                         columns=['observationoffset', 'patientunitstayid'] + variables,
                         mode='r')
    # sometimes it's empty
    if pat_df.empty:
        return None
    if not upto_in_minutes is None:
        pat_df = pat_df.loc[0:upto_in_minutes*60]
    # convert the offset to a TimedeltaIndex (necessary for resampling)
    pat_df.observationoffset = pd.TimedeltaIndex(pat_df.observationoffset, unit='m')
    pat_df.set_index('observationoffset', inplace=True)
    pat_df.sort_index(inplace=True)
    # resample by time
    pat_df_resampled = pat_df.resample(str(resample_factor_in_min) + 'T').median()  # pandas ignores NA in median by default
    # rename pid, cast to int
    pat_df_resampled.rename(columns={'patientunitstayid': 'pid'}, inplace=True)
    pat_df_resampled['pid'] = np.int32(pat_df_resampled['pid'])
    # get offsets in minutes from index
    pat_df_resampled['offset'] = np.int32(pat_df_resampled.index.total_seconds()/60)
    return pat_df_resampled 
开发者ID:ratschlab,项目名称:RGAN,代码行数:27,代码来源:data_utils.py

示例13: get_weather_dict

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import mode [as 别名]
def get_weather_dict(self,data_dir):
        t0 = time()
        filename = '../data_raw/' + data_dir.split('/')[-2] + '_weather.csv.dict.pickle'
        dumpload = DumpLoad( filename)
        if dumpload.isExisiting():
            return dumpload.load()
        
        resDict = {}
        df = self.load_weatherdf(data_dir)
        for index, row in df.iterrows():
            resDict[row['time_slotid']] = (index, row['weather'], row['temparature'], row['pm25'])
        for name, group in df.groupby('time_date'):
            resDict[name] = (-1, mode(group['weather'])[0][0], mode(group['temparature'])[0][0], mode(group['pm25'])[0][0])
            
       
        dumpload.dump(resDict)
        print "dump weather dict:", round(time()-t0, 3), "s"
        return resDict 
开发者ID:LevinJ,项目名称:Supply-demand-forecasting,代码行数:20,代码来源:weather.py

示例14: find_history_data

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import mode [as 别名]
def find_history_data(self, row, history_dict=None,):
        start_district_id = row.iloc[0]
        time_id = row.iloc[1]
        index = ['history_mean','history_median','history_mode','history_plus_mean','history_plus_median', 'history_plus_mode']

        min_list = self.__get_historylist_from_dict(history_dict, start_district_id, time_id)
        plus_list1 = self.__get_historylist_from_dict(history_dict, start_district_id, time_id-1)
        plus_list2 = self.__get_historylist_from_dict(history_dict, start_district_id, time_id-2)
        plus_list = np.array((plus_list1 + plus_list2 + min_list))
        min_list = np.array(min_list)
        
        res =pd.Series([min_list.mean(), np.median(min_list), mode(min_list)[0][0], plus_list.mean(), np.median(plus_list),mode(plus_list)[0][0]], index = index)
        
        return res
    
        return pd.Series(res, index = ['history_mean', 'history_mode', 'history_median']) 
开发者ID:LevinJ,项目名称:Supply-demand-forecasting,代码行数:18,代码来源:historicaldata.py

示例15: predict

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import mode [as 别名]
def predict(self, X):
        """
        Predicts the output (y) of a given matrix X

        Parameters
        ----------
        X : numerical or ordinal matrix of values corresponding to some output

        Returns
        -------
        The predict values corresponding to the inputs
        """

        votes = np.zeros(shape=(self.num_trees, X.shape[0]))
        for i, tree in enumerate(self.forest):
            votes[i] = tree.predict(X)

        predictions = np.zeros(shape=X.shape[0])
        if isinstance(self, RegressionForest):
            predictions = votes.mean(axis=0)
        else:
            # print(votes)
            predictions = np.squeeze(mode(votes, axis=0)[0])

        return predictions 
开发者ID:OpenIDEA-YunanUniversity,项目名称:ycimpute,代码行数:27,代码来源:random_forest.py


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