本文整理汇总了Python中scipy.stats.sem方法的典型用法代码示例。如果您正苦于以下问题:Python stats.sem方法的具体用法?Python stats.sem怎么用?Python stats.sem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy.stats
的用法示例。
在下文中一共展示了stats.sem方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_sem
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import sem [as 别名]
def test_sem(self):
# example from stats.sem doc
a = np.arange(20).reshape(5,4)
am = np.ma.array(a)
r = stats.sem(a,ddof=1)
rm = stats.mstats.sem(am, ddof=1)
assert_allclose(r, 2.82842712, atol=1e-5)
assert_allclose(rm, 2.82842712, atol=1e-5)
for n in self.get_n():
x, y, xm, ym = self.generate_xy_sample(n)
assert_almost_equal(stats.mstats.sem(xm, axis=None, ddof=0),
stats.sem(x, axis=None, ddof=0), decimal=13)
assert_almost_equal(stats.mstats.sem(ym, axis=None, ddof=0),
stats.sem(y, axis=None, ddof=0), decimal=13)
assert_almost_equal(stats.mstats.sem(xm, axis=None, ddof=1),
stats.sem(x, axis=None, ddof=1), decimal=13)
assert_almost_equal(stats.mstats.sem(ym, axis=None, ddof=1),
stats.sem(y, axis=None, ddof=1), decimal=13)
示例2: optimally_reblocked
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import sem [as 别名]
def optimally_reblocked(data):
"""
Find optimal reblocking of input data. Takes in pandas
DataFrame of raw data to reblock, returns DataFrame
of reblocked data.
"""
opt = opt_block(data)
n_reblock = int(np.amax(opt))
rb_data = reblock_by2(data, n_reblock)
serr = rb_data.sem(axis=0)
d = {
"mean": rb_data.mean(axis=0),
"standard error": serr,
"standard error error": serr / np.sqrt(2 * (len(rb_data) - 1)),
"reblocks": n_reblock,
}
return pd.DataFrame(d)
示例3: test_sem
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import sem [as 别名]
def test_sem(self):
# This is not in R, so used:
# sqrt(var(testcase)*3/4)/sqrt(3)
# y = stats.sem(self.shoes[0])
# assert_approx_equal(y,0.775177399)
with suppress_warnings() as sup, np.errstate(invalid="ignore"):
sup.filter(RuntimeWarning, "Degrees of freedom <= 0 for slice")
y = stats.sem(self.scalar_testcase)
assert_(np.isnan(y))
y = stats.sem(self.testcase)
assert_approx_equal(y, 0.6454972244)
n = len(self.testcase)
assert_allclose(stats.sem(self.testcase, ddof=0) * np.sqrt(n/(n-2)),
stats.sem(self.testcase, ddof=2))
x = np.arange(10.)
x[9] = np.nan
assert_equal(stats.sem(x), np.nan)
assert_equal(stats.sem(x, nan_policy='omit'), 0.9128709291752769)
assert_raises(ValueError, stats.sem, x, nan_policy='raise')
assert_raises(ValueError, stats.sem, x, nan_policy='foobar')
示例4: mean_confidence_interval
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import sem [as 别名]
def mean_confidence_interval(data, confidence=0.95):
a = 1.0*np.array(data)
n = len(a)
m = np.mean(a)
se = stats.sem(a)
h = se * stats.t._ppf((1+confidence)/2., n-1)
return m,h
示例5: evaluate_cross_validation
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import sem [as 别名]
def evaluate_cross_validation(clf, X, y, K):
# create a k-fold cross validation iterator
cv = KFold(len(y), K, shuffle=True, random_state=0)
# by default the score used is the one returned by score method of the estimator (accuracy)
scores = cross_val_score(clf, X, y, cv=cv)
print "Scores: ", (scores)
print ("Mean score: {0:.3f} (+/-{1:.3f})".format(np.mean(scores), sem(scores)))
# Confusion Matrix and Results
开发者ID:its-izhar,项目名称:Emotion-Recognition-Using-SVMs,代码行数:12,代码来源:Train Classifier and Test Video Feed.py
示例6: reblock_summary
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import sem [as 别名]
def reblock_summary(df, nblocks):
df = reblock(df, nblocks)
serr = df.sem()
d = {
"mean": df.mean(axis=0),
"standard error": serr,
"standard error error": serr / np.sqrt(2 * (len(df) - 1)),
"n_blocks": nblocks,
}
return pd.DataFrame(d)
示例7: opt_block
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import sem [as 别名]
def opt_block(df):
"""
Finds optimal block size for each variable in a dataset
df is a dataframe where each row is a sample and each column is a calculated quantity
reblock each column over samples to find the best block size
Returns optimal_block, a 1D array with the optimal size for each column in df
"""
newdf = df.copy()
iblock = 0
ndata, nvariables = tuple(df.shape[:2])
optimal_block = np.array([float("NaN")] * nvariables)
serr0 = df.sem(axis=0).values
statslist = []
while newdf.shape[0] > 1:
serr = newdf.sem(axis=0).values
serrerr = serr / (2 * (newdf.shape[0] - 1)) ** 0.5
statslist.append((iblock, serr.copy()))
n = newdf.shape[0]
lasteven = n - int(n % 2 == 1)
newdf = (newdf[:lasteven:2] + newdf[1::2].values) / 2
iblock += 1
for iblock, serr in reversed(statslist):
B3 = 2 ** (3 * iblock)
inds = np.where(B3 >= 2 * ndata * (serr / serr0) ** 4)[0]
optimal_block[inds] = iblock
return optimal_block
示例8: test_reblocking
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import sem [as 别名]
def test_reblocking():
"""
Tests reblocking against known distribution.
"""
from scipy.stats import sem
def corr_data(N, L):
"""
Creates correlated data. Taken from
https://pyblock.readthedocs.io/en/latest/tutorial.html.
"""
return np.convolve(np.random.randn(2 ** N), np.ones(2 ** L) / 10, "same")
n = 11
cols = ["test_data1", "test_data2"]
dat1 = corr_data(n, 4)
dat2 = corr_data(n, 7)
test_data = pd.DataFrame(data={cols[0]: dat1, cols[1]: dat2})
reblocked_data = optimally_reblocked(test_data[cols])
for c in cols:
row = reblocked_data.loc[c]
reblocks = reblocked_data["reblocks"].values[0]
std_err = sem(reblock_by2(test_data, reblocks, c))
std_err_err = std_err / np.sqrt(2 * (2 ** (n - reblocks) - 1))
assert np.isclose(
row["mean"], np.mean(test_data[c]), 1e-10, 1e-12
), "Means are not equal"
assert np.isclose(
row["standard error"], std_err, 1e-10, 1e-12
), "Standard errors are not equal"
assert np.isclose(
row["standard error error"], std_err_err, 1e-10, 1e-12
), "Standard error errors are not equal"
statlist = ["mean", "sem", lambda x: x.sem() / np.sqrt(2 * (len(x) - 1))]
rb1 = reblock(test_data, len(test_data) // 4).agg(statlist).T
rb2 = reblock_by2(test_data, 2).agg(statlist).T
for c in rb1.columns:
assert np.isclose(rb1[c], rb2[c], 1e-10, 1e-12).all(), (c, rb1[c], rb2[c])
示例9: test_nansem
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import sem [as 别名]
def test_nansem(self, ddof):
from scipy.stats import sem
with np.errstate(invalid='ignore'):
self.check_funs(nanops.nansem, sem, allow_complex=False,
allow_str=False, allow_date=False,
allow_tdelta=False, allow_obj='convert', ddof=ddof)
示例10: test_ops_general
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import sem [as 别名]
def test_ops_general():
ops = [('mean', np.mean),
('median', np.median),
('std', np.std),
('var', np.var),
('sum', np.sum),
('prod', np.prod),
('min', np.min),
('max', np.max),
('first', lambda x: x.iloc[0]),
('last', lambda x: x.iloc[-1]),
('count', np.size), ]
try:
from scipy.stats import sem
except ImportError:
pass
else:
ops.append(('sem', sem))
df = DataFrame(np.random.randn(1000))
labels = np.random.randint(0, 50, size=1000).astype(float)
for op, targop in ops:
result = getattr(df.groupby(labels), op)().astype(float)
expected = df.groupby(labels).agg(targop)
try:
tm.assert_frame_equal(result, expected)
except BaseException as exc:
exc.args += ('operation: %s' % op, )
raise
示例11: test_sem
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import sem [as 别名]
def test_sem(self):
"""
this is not in R, so used
sqrt(var(testcase)*3/4)/sqrt(3)
"""
#y = stats.sem(self.shoes[0])
#assert_approx_equal(y,0.775177399)
y = mstats.sem(self.testcase)
assert_almost_equal(y,0.6454972244)
示例12: test_sem
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import sem [as 别名]
def test_sem(self):
# This is not in R, so used:
# sqrt(var(testcase)*3/4)/sqrt(3)
# y = stats.sem(self.shoes[0])
# assert_approx_equal(y,0.775177399)
y = stats.sem(self.testcase)
assert_approx_equal(y,0.6454972244)
示例13: ax_plot_lines
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import sem [as 别名]
def ax_plot_lines(ax, xs, ys, colors, shapes, linestyles,
errorbar=False, linewidth=LINEWIDTH):
lines = []
for (x, y, c, s, l) in zip(xs, ys, colors, shapes, linestyles):
if errorbar:
# y should be a list of lists in this case
mean = [np.mean(yl) for yl in y]
error = [ss.sem(yl) for yl in y]
l = ax.errorbar(x, mean, yerr=error, color=c,
marker=s, linestyle=l, ecolor=c)
else:
l, = ax.plot(x, y, color=c, marker=s, linestyle=l, linewidth=linewidth)
lines.append(l)
return lines
示例14: get_relation_strength
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import sem [as 别名]
def get_relation_strength(table_file, top=10, normalize=False,
return_sem=False, return_all=False):
type_list = load_all_pairs(table_file)
scores = {k: [abs(v.combined_score) for v in type_list[k][:top]]
for k in type_list}
mean = {k: np.mean(scores[k]) for k in type_list}
if return_all:
return scores, mean, {k: ss.sem(scores[k]) for k in type_list}
elif return_sem:
return mean, {k: ss.sem(scores[k]) for k in type_list}
elif normalize:
max_v = max(mean.values())
return {k: mean[k] / max_v for k in mean}
else:
return mean
示例15: get_confidence_interval
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import sem [as 别名]
def get_confidence_interval(class_accuracies, confidence):
print(st.t.interval(CONFIDENCE_LEVEL, len(class_accuracies)-1,
loc=np.mean(class_accuracies),
scale=st.sem(class_accuracies)))