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


Python stats.normaltest方法代碼示例

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


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

示例1: omni_normtest

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import normaltest [as 別名]
def omni_normtest(resids, axis=0):
    """
    Omnibus test for normality

    Parameters
    -----------
    resid : array-like
    axis : int, optional
        Default is 0

    Returns
    -------
    Chi^2 score, two-tail probability
    """
    #TODO: change to exception in summary branch and catch in summary()
    #behavior changed between scipy 0.9 and 0.10
    resids = np.asarray(resids)
    n = resids.shape[axis]
    if n < 8:
        from warnings import warn
        warn("omni_normtest is not valid with less than 8 observations; %i "
             "samples were given." % int(n), ValueWarning)
        return np.nan, np.nan

    return stats.normaltest(resids, axis=axis) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:27,代碼來源:stattools.py

示例2: get_normality

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import normaltest [as 別名]
def get_normality(field_name, field_values, field_type, general_type, scale):
    normality = None
    if general_type is 'q':
        try:
            d = field_values.astype(np.float)
            normality_test_result = sc_stats.normaltest(d)
            if normality_test_result:
                statistic = normality_test_result.statistic
                pvalue = normality_test_result.pvalue
                if pvalue < 0.05:
                    normality = True
                else:
                    normality = False
        except ValueError:
            normality = None
    return normality 
開發者ID:MacroConnections,項目名稱:DIVE-backend,代碼行數:18,代碼來源:field_properties.py

示例3: is_log_scale_needed

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import normaltest [as 別名]
def is_log_scale_needed(x_org):
        x = np.array(x_org[~pd.isnull(x_org)])
        # first scale on raw data
        x = preprocessing.scale(x)
        # second scale on log data
        x_log = preprocessing.scale(np.log(x - np.min(x) + 1))

        # the old approach, let's check how new approach will work
        # original_skew = np.abs(stats.skew(x))
        # log_skew = np.abs(stats.skew(x_log))
        # return log_skew < original_skew
        ########################################################################
        # p is probability of being normal distributions
        k2, p1 = stats.normaltest(x)
        k2, p2 = stats.normaltest(x_log)

        return p2 > p1 
開發者ID:mljar,項目名稱:mljar-supervised,代碼行數:19,代碼來源:preprocessing_utils.py

示例4: test_evidence

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import normaltest [as 別名]
def test_evidence(self):
        # 2 sigma tolerance
        tolerance = 2.0*np.sqrt(self.work.NS.state.info/self.work.NS.Nlive)
        print('2-sigma statistic error in logZ: {0:0.3f}'.format(tolerance))
        print('Analytic logZ {0}'.format(self.model.analytic_log_Z))
        print('Estimated logZ {0}'.format(self.work.NS.logZ))
        pos=self.work.posterior_samples['x']
        #t,pval=stats.kstest(pos,self.model.distr.cdf)
        stat,pval = stats.normaltest(pos.T)
        print('Normal test p-value {0}'.format(str(pval)))
        plt.figure()
        plt.hist(pos.ravel(),density=True)
        x=np.linspace(self.model.bounds[0][0],self.model.bounds[0][1],100)
        plt.plot(x,self.model.distr.pdf(x))
        plt.title('NormalTest pval = {0}'.format(pval))
        plt.savefig('posterior.png')
        plt.figure()
        plt.plot(pos.ravel(),',')
        plt.title('chain')
        plt.savefig('chain.png')
        self.assertTrue(np.abs(self.work.NS.logZ - GaussianModel.analytic_log_Z)<tolerance, 'Incorrect evidence for normalised distribution: {0:.3f} instead of {1:.3f}'.format(self.work.NS.logZ,GaussianModel.analytic_log_Z ))
        self.assertTrue(pval>0.01,'Normaltest test failed: KS stat = {0}'.format(pval)) 
開發者ID:johnveitch,項目名稱:cpnest,代碼行數:24,代碼來源:test_1d.py

示例5: _normaltest

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import normaltest [as 別名]
def _normaltest(self, x):
        """
        Compute test for normal distribution.

        Null hypothesis: x comes from a normal distribution
        p < alpha suggests the null hypothesis can be rejected.
        """
        if len(x.values[~np.isnan(x.values)]) >= 20:
            stat, p = stats.normaltest(x.values, nan_policy='omit')
        else:
            p = None
        # dropna=False argument in pivot_table does not function as expected
        # return -1 instead of None
        if pd.isnull(p):
            return -1
        return p 
開發者ID:tompollard,項目名稱:tableone,代碼行數:18,代碼來源:tableone.py

示例6: test_normalitytests

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import normaltest [as 別名]
def test_normalitytests():
    # numbers verified with R: dagoTest in package fBasics
    st_normal, st_skew, st_kurt = (3.92371918, 1.98078826, -0.01403734)
    pv_normal, pv_skew, pv_kurt = (0.14059673, 0.04761502, 0.98880019)
    x = np.array((-2,-1,0,1,2,3)*4)**2
    yield assert_array_almost_equal, stats.normaltest(x), (st_normal, pv_normal)
    yield assert_array_almost_equal, stats.skewtest(x), (st_skew, pv_skew)
    yield assert_array_almost_equal, stats.kurtosistest(x), (st_kurt, pv_kurt) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:10,代碼來源:test_stats.py

示例7: test_vs_nonmasked

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import normaltest [as 別名]
def test_vs_nonmasked(self):
        x = np.array((-2,-1,0,1,2,3)*4)**2
        assert_array_almost_equal(mstats.normaltest(x),
                                  stats.normaltest(x))
        assert_array_almost_equal(mstats.skewtest(x),
                                  stats.skewtest(x))
        assert_array_almost_equal(mstats.kurtosistest(x),
                                  stats.kurtosistest(x))

        funcs = [stats.normaltest, stats.skewtest, stats.kurtosistest]
        mfuncs = [mstats.normaltest, mstats.skewtest, mstats.kurtosistest]
        x = [1, 2, 3, 4]
        for func, mfunc in zip(funcs, mfuncs):
            assert_raises(ValueError, func, x)
            assert_raises(ValueError, mfunc, x) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:17,代碼來源:test_mstats_basic.py

示例8: test_axis_None

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import normaltest [as 別名]
def test_axis_None(self):
        # Test axis=None (equal to axis=0 for 1-D input)
        x = np.array((-2,-1,0,1,2,3)*4)**2
        assert_allclose(mstats.normaltest(x, axis=None), mstats.normaltest(x))
        assert_allclose(mstats.skewtest(x, axis=None), mstats.skewtest(x))
        assert_allclose(mstats.kurtosistest(x, axis=None),
                        mstats.kurtosistest(x)) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:9,代碼來源:test_mstats_basic.py

示例9: test_maskedarray_input

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import normaltest [as 別名]
def test_maskedarray_input(self):
        # Add some masked values, test result doesn't change
        x = np.array((-2,-1,0,1,2,3)*4)**2
        xm = np.ma.array(np.r_[np.inf, x, 10],
                         mask=np.r_[True, [False] * x.size, True])
        assert_allclose(mstats.normaltest(xm), stats.normaltest(x))
        assert_allclose(mstats.skewtest(xm), stats.skewtest(x))
        assert_allclose(mstats.kurtosistest(xm), stats.kurtosistest(x)) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:10,代碼來源:test_mstats_basic.py

示例10: test_nd_input

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import normaltest [as 別名]
def test_nd_input(self):
        x = np.array((-2,-1,0,1,2,3)*4)**2
        x_2d = np.vstack([x] * 2).T
        for func in [mstats.normaltest, mstats.skewtest, mstats.kurtosistest]:
            res_1d = func(x)
            res_2d = func(x_2d)
            assert_allclose(res_2d[0], [res_1d[0]] * 2)
            assert_allclose(res_2d[1], [res_1d[1]] * 2) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:10,代碼來源:test_mstats_basic.py

示例11: test_normaltest_result_attributes

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import normaltest [as 別名]
def test_normaltest_result_attributes(self):
        x = np.array((-2, -1, 0, 1, 2, 3)*4)**2
        res = mstats.normaltest(x)
        attributes = ('statistic', 'pvalue')
        check_named_results(res, attributes, ma=True) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:7,代碼來源:test_mstats_basic.py

示例12: is_normal

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import normaltest [as 別名]
def is_normal(self, column):
        new_data_result = stats.normaltest(self.new_data[column])
        historical_data_result = stats.normaltest(self.historical_data[column])
        if new_data_result.pvalue > 0.05 and historical_data_result.pvalue > 0.05:
            return True
        return False 
開發者ID:EricSchles,項目名稱:drifter_ml,代碼行數:8,代碼來源:columnar_tests.py

示例13: _normaltest

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import normaltest [as 別名]
def _normaltest(v):
    return normaltest(v).pvalue 
開發者ID:MacroConnections,項目名稱:DIVE-backend,代碼行數:4,代碼來源:score_specs.py

示例14: sets_normal

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import normaltest [as 別名]
def sets_normal(THRESHOLD, *args):
    '''
    If normalP is less than threshold, not considered normal
    '''
    normal = True;
    for arg in args:
        if len(arg) < 8:
            return False
        if stats.normaltest(arg)[1] < THRESHOLD:
            normal = False;

    return normal 
開發者ID:MacroConnections,項目名稱:DIVE-backend,代碼行數:14,代碼來源:utilities.py

示例15: _check_normality

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import normaltest [as 別名]
def _check_normality(dist):
    '''
    Method to check if the samples in dist differs from a normal distribution.
    Return true if the dist is likely to be gaussian.
    '''
    _, pvalue = normaltest(dist)
    if (pvalue > 0.05):
        # The samples in dist came from a normal distribution with 95% confidence
        return True
    else:
        return False 
開發者ID:shagunsodhani,項目名稱:pregel,代碼行數:13,代碼來源:ptest.py


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