本文整理汇总了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)
示例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
示例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
示例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))
示例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
示例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)
示例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)
示例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))
示例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))
示例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)
示例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)
示例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
示例13: _normaltest
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import normaltest [as 别名]
def _normaltest(v):
return normaltest(v).pvalue
示例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
示例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