當前位置: 首頁>>代碼示例>>Python>>正文


Python stats.describe方法代碼示例

本文整理匯總了Python中scipy.stats.describe方法的典型用法代碼示例。如果您正苦於以下問題:Python stats.describe方法的具體用法?Python stats.describe怎麽用?Python stats.describe使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在scipy.stats的用法示例。


在下文中一共展示了stats.describe方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_describe

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import describe [as 別名]
def test_describe():
    x = np.vstack((np.ones((3,4)),2*np.ones((2,4))))
    nc, mmc = (5, ([1., 1., 1., 1.], [2., 2., 2., 2.]))
    mc = np.array([1.4, 1.4, 1.4, 1.4])
    vc = np.array([0.3, 0.3, 0.3, 0.3])
    skc = [0.40824829046386357]*4
    kurtc = [-1.833333333333333]*4
    n, mm, m, v, sk, kurt = stats.describe(x)
    assert_equal(n, nc)
    assert_equal(mm, mmc)
    assert_equal(m, mc)
    assert_equal(v, vc)
    assert_array_almost_equal(sk, skc, decimal=13)  # not sure about precision
    assert_array_almost_equal(kurt, kurtc, decimal=13)
    n, mm, m, v, sk, kurt = stats.describe(x.T, axis=1)
    assert_equal(n, nc)
    assert_equal(mm, mmc)
    assert_equal(m, mc)
    assert_equal(v, vc)
    assert_array_almost_equal(sk, skc, decimal=13)  # not sure about precision
    assert_array_almost_equal(kurt, kurtc, decimal=13) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:23,代碼來源:test_stats.py

示例2: stat

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import describe [as 別名]
def stat(seq_length, type):
    print('Seq len info :')
    seq_len = np.asarray(seq_length)
    idx = np.arange(0, len(seq_len), dtype=np.int32)
    print(stats.describe(seq_len))
    plt.figure(figsize=(16, 9))
    plt.subplot(121)
    plt.plot(idx[:], seq_len[:], 'ro')
    plt.grid(True)
    plt.xlabel('index')
    plt.ylabel('seq_len')
    plt.title('Scatter Plot')

    plt.subplot(122)
    plt.hist(seq_len, bins=10, label=['seq_len'])
    plt.grid(True)
    plt.xlabel('seq_len')
    plt.ylabel('freq')
    plt.title('Histogram')
    plt.savefig(type + '_len_stats.jpg', format='jpg') 
開發者ID:shiningliang,項目名稱:CCKS2019-IPRE,代碼行數:22,代碼來源:pretrain_embedding.py

示例3: test_describe_axis_none

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import describe [as 別名]
def test_describe_axis_none(self):
        x = np.vstack((np.ones((3, 4)), 2 * np.ones((2, 4))))

        # expected values
        e_nobs, e_minmax = (20, (1.0, 2.0))
        e_mean = 1.3999999999999999
        e_var = 0.25263157894736848
        e_skew = 0.4082482904638634
        e_kurt = -1.8333333333333333

        # actual values
        a = stats.describe(x, axis=None)

        assert_equal(a.nobs, e_nobs)
        assert_almost_equal(a.minmax, e_minmax)
        assert_almost_equal(a.mean, e_mean)
        assert_almost_equal(a.variance, e_var)
        assert_array_almost_equal(a.skewness, e_skew, decimal=13)
        assert_array_almost_equal(a.kurtosis, e_kurt, decimal=13) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:21,代碼來源:test_stats.py

示例4: merge

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import describe [as 別名]
def merge(self, frame):
        """
        Add another DataFrame to the accumulated stats for each column.
        Parameters
        ----------
        frame: pandas DataFrame we will update our stats counter with.
        """
        for column_name, _ in self._column_stats.items():
            data_arr = frame[[column_name]].values
            count, min_max_tup, mean, _, _, _ = \
                scistats.describe(data_arr)
            stats_counter = StatCounter()
            stats_counter.n = count
            stats_counter.mu = mean
            stats_counter.m2 = np.sum((data_arr - mean) ** 2)
            stats_counter.minValue, stats_counter.maxValue = min_max_tup
            self._column_stats[column_name] = self._column_stats[
                column_name].mergeStats(stats_counter)
        return self 
開發者ID:sparklingpandas,項目名稱:sparklingpandas,代碼行數:21,代碼來源:pstatcounter.py

示例5: examples_normexpand

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import describe [as 別名]
def examples_normexpand():
    skewnorm = SkewNorm_gen()
    rvs = skewnorm.rvs(5,size=100)
    normexpan = NormExpan_gen(rvs, mode='sample')

    smvsk = stats.describe(rvs)[2:]
    print('sample: mu,sig,sk,kur')
    print(smvsk)

    dmvsk = normexpan.stats(moments='mvsk')
    print('normexpan: mu,sig,sk,kur')
    print(dmvsk)
    print('mvsk diff distribution - sample')
    print(np.array(dmvsk) - np.array(smvsk))
    print('normexpan attributes mvsk')
    print(mc2mvsk(normexpan.cnt))
    print(normexpan.mvsk)

    mnc = mvsk2mnc(dmvsk)
    mc = mnc2mc(mnc)
    print('central moments')
    print(mc)
    print('non-central moments')
    print(mnc)


    pdffn = pdf_moments(mc)
    print('\npdf approximation from moments')
    print('pdf at', mc[0]-1,mc[0]+1)
    print(pdffn([mc[0]-1,mc[0]+1]))
    print(normexpan.pdf([mc[0]-1,mc[0]+1])) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:33,代碼來源:ex_extras.py

示例6: test_mvsk

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import describe [as 別名]
def test_mvsk(self):
        mvsk = stats.describe(self.rvs)[-4:]
        assert_allclose(self.dist2.mvsk, mvsk, rtol=1e-12) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:5,代碼來源:test_norm_expan.py

示例7: __init__

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import describe [as 別名]
def __init__(self,args, **kwds):
        #todo: replace with super call
        distributions.rv_continuous.__init__(self,
            name = 'Normal Expansion distribution', shapes = ' ',
            extradoc = '''
        The distribution is defined as the Gram-Charlier expansion of
        the normal distribution using the first four moments. The pdf
        is given by

        pdf(x) = (1+ skew/6.0 * H(xc,3) + kurt/24.0 * H(xc,4))*normpdf(xc)

        where xc = (x-mu)/sig is the standardized value of the random variable
        and H(xc,3) and H(xc,4) are Hermite polynomials

        Note: This distribution has to be parameterized during
        initialization and instantiation, and does not have a shape
        parameter after instantiation (similar to frozen distribution
        except for location and scale.) Location and scale can be used
        as with other distributions, however note, that they are relative
        to the initialized distribution.
        '''  )
        #print args, kwds
        mode = kwds.get('mode', 'sample')

        if mode == 'sample':
            mu,sig,sk,kur = stats.describe(args)[2:]
            self.mvsk = (mu,sig,sk,kur)
            cnt = mvsk2mc((mu,sig,sk,kur))
        elif mode == 'mvsk':
            cnt = mvsk2mc(args)
            self.mvsk = args
        elif mode == 'centmom':
            cnt = args
            self.mvsk = mc2mvsk(cnt)
        else:
            raise ValueError("mode must be 'mvsk' or centmom")

        self.cnt = cnt
        #self.mvsk = (mu,sig,sk,kur)
        #self._pdf = pdf_moments(cnt)
        self._pdf = pdf_mvsk(self.mvsk) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:43,代碼來源:extras.py

示例8: compute_distances

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import describe [as 別名]
def compute_distances(self, X, Y):
        print('Computing intra-domain distance matrices...')

        if not self.gpu:
            C1 = sp.spatial.distance.cdist(X, X, metric=self.metric)
            C2 = sp.spatial.distance.cdist(Y, Y, metric=self.metric)
            if self.normalize_dists == 'max':
                print('here')
                C1 /= C1.max()
                C2 /= C2.max()
            elif self.normalize_dists == 'mean':
                C1 /= C1.mean()
                C2 /= C2.mean()
            elif self.normalize_dists == 'median':
                C1 /= np.median(C1)
                C2 /= np.median(C2)
        else:
            C1 = cdist(X, X, metric=self.metric, returnAsGPU=True)
            C2 = cdist(Y, Y, metric=self.metric, returnAsGPU=True)
            if self.normalize_dists == 'max':
                C1.divide(float(np.max(C1.asarray())))
                C2.divide(float(np.max(C2.asarray())))
            elif self.normalize_dists == 'mean':
                C1.divide(float(np.mean(C1.asarray())))
                C2.divide(float(np.mean(C2.asarray())))
            elif self.normalize_dists == 'median':
                raise NotImplemented(
                    "Median normalization not implemented in GPU yet")

        stats_C1 = describe(C1.flatten())
        stats_C2 = describe(C2.flatten())

        for (k, C, v) in [('C1', C1, stats_C1), ('C2', C2, stats_C2)]:
            print('Stats Distance Matrix {}. mean: {:8.2f}, median: {:8.2f},\
             min: {:8.2f}, max:{:8.2f}'.format(k, v.mean, np.median(C), v.minmax[0], v.minmax[1]))

        self.C1, self.C2 = C1, C2 
開發者ID:dmelis,項目名稱:otalign,代碼行數:39,代碼來源:gw_optim.py

示例9: test_describe

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import describe [as 別名]
def test_describe(self):
        for n in self.get_n():
            x, y, xm, ym = self.generate_xy_sample(n)
            r = stats.describe(x, ddof=1)
            rm = stats.mstats.describe(xm, ddof=1)
            for ii in range(6):
                assert_almost_equal(np.asarray(r[ii]),
                                    np.asarray(rm[ii]),
                                    decimal=12) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:11,代碼來源:test_mstats_basic.py

示例10: test_describe_result_attributes

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import describe [as 別名]
def test_describe_result_attributes(self):
        actual = mstats.describe(np.arange(5))
        attributes = ('nobs', 'minmax', 'mean', 'variance', 'skewness',
                      'kurtosis')
        check_named_results(actual, attributes, ma=True) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:7,代碼來源:test_mstats_basic.py

示例11: test_describe_scalar

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import describe [as 別名]
def test_describe_scalar(self):
        with suppress_warnings() as sup, np.errstate(invalid="ignore"):
            sup.filter(RuntimeWarning, "Degrees of freedom <= 0 for slice")
            n, mm, m, v, sk, kurt = stats.describe(4.)
        assert_equal(n, 1)
        assert_equal(mm, (4.0, 4.0))
        assert_equal(m, 4.0)
        assert_(np.isnan(v))
        assert_array_almost_equal(sk, 0.0, decimal=13)
        assert_array_almost_equal(kurt, -3.0, decimal=13) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:12,代碼來源:test_stats.py

示例12: test_describe_numbers

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import describe [as 別名]
def test_describe_numbers(self):
        x = np.vstack((np.ones((3,4)), 2 * np.ones((2,4))))
        nc, mmc = (5, ([1., 1., 1., 1.], [2., 2., 2., 2.]))
        mc = np.array([1.4, 1.4, 1.4, 1.4])
        vc = np.array([0.3, 0.3, 0.3, 0.3])
        skc = [0.40824829046386357] * 4
        kurtc = [-1.833333333333333] * 4
        n, mm, m, v, sk, kurt = stats.describe(x)
        assert_equal(n, nc)
        assert_equal(mm, mmc)
        assert_equal(m, mc)
        assert_equal(v, vc)
        assert_array_almost_equal(sk, skc, decimal=13)
        assert_array_almost_equal(kurt, kurtc, decimal=13)
        n, mm, m, v, sk, kurt = stats.describe(x.T, axis=1)
        assert_equal(n, nc)
        assert_equal(mm, mmc)
        assert_equal(m, mc)
        assert_equal(v, vc)
        assert_array_almost_equal(sk, skc, decimal=13)
        assert_array_almost_equal(kurt, kurtc, decimal=13)

        x = np.arange(10.)
        x[9] = np.nan

        nc, mmc = (9, (0.0, 8.0))
        mc = 4.0
        vc = 7.5
        skc = 0.0
        kurtc = -1.2300000000000002
        n, mm, m, v, sk, kurt = stats.describe(x, nan_policy='omit')
        assert_equal(n, nc)
        assert_equal(mm, mmc)
        assert_equal(m, mc)
        assert_equal(v, vc)
        assert_array_almost_equal(sk, skc)
        assert_array_almost_equal(kurt, kurtc, decimal=13)

        assert_raises(ValueError, stats.describe, x, nan_policy='raise')
        assert_raises(ValueError, stats.describe, x, nan_policy='foobar') 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:42,代碼來源:test_stats.py

示例13: test_describe_result_attributes

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import describe [as 別名]
def test_describe_result_attributes(self):
        actual = stats.describe(np.arange(5))
        attributes = ('nobs', 'minmax', 'mean', 'variance', 'skewness',
                      'kurtosis')
        check_named_results(actual, attributes) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:7,代碼來源:test_stats.py

示例14: test_describe_empty

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import describe [as 別名]
def test_describe_empty(self):
        assert_raises(ValueError, stats.describe, []) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:4,代碼來源:test_stats.py

示例15: __init__

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import describe [as 別名]
def __init__(self,metric_name, measurements):
        self._metric_name = metric_name
        self._measurements = measurements
        print("measurements:",self._measurements)
        array=np.array(self._measurements)
        self._stats = stats.describe(array)
        self._bayes_mvs = stats.bayes_mvs(array) 
開發者ID:exasol,項目名稱:script-languages,代碼行數:9,代碼來源:__init__.py


注:本文中的scipy.stats.describe方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。