本文整理汇总了Python中scipy.stats.f_oneway方法的典型用法代码示例。如果您正苦于以下问题:Python stats.f_oneway方法的具体用法?Python stats.f_oneway怎么用?Python stats.f_oneway使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy.stats
的用法示例。
在下文中一共展示了stats.f_oneway方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test__batch
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import f_oneway [as 别名]
def test__batch():
rs = np.random.RandomState(1234)
# p-values for ANOVA should all be ~0 (large group differences) before
# batch correction
y = [rs.normal(size=(100, 1000)) + f for f in [5, 0, 0]]
assert np.allclose(sstats.f_oneway(*y)[1], 0)
# F-values for ANOVA should all be ~0 (no group differences) after batch
# correction; p-values returned here are sometimes NaN so not a good test
out = correct._batch_correct(y)
assert np.allclose(sstats.f_oneway(*out)[0], 0)
# mean expressions after correction should be ~equal
assert np.allclose([o.mean() for o in out], 1.24871965683026)
with pytest.raises(ValueError):
correct._batch_correct([y[0]])
示例2: Anova
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import f_oneway [as 别名]
def Anova(self):
"""
Calculate the F-Score (One Way Anova) for each of Categorical Variables with all the Continuous Variables.
Output --> List of Continuous Variables, whose pValue is < 0.05
"""
target = self.target
AnovaList = []
print('Performing ANOVA...')
for CategoricalVar in tqdm(self.CategoricalFeatures):
temp_df = self.df[[CategoricalVar, target]].dropna()
try:
f,p = stats.f_oneway(*[list(temp_df[temp_df[CategoricalVar]==name][target]) for name in set(temp_df[CategoricalVar])])
AnovaList.append(dict(Categorical = CategoricalVar, PValue = p))
except:
# Do Nothing. Skip.
1==1
Anova_df = pd.DataFrame(AnovaList)
if Anova_df.shape[0]>0:
Anova_df = Anova_df[Anova_df['PValue']<=0.05]
Anova_df.sort_values(['PValue'],ascending = True, inplace=True)
return Anova_df
示例3: Anova
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import f_oneway [as 别名]
def Anova(self):
"""
Calculate the F-Score (One Way Anova) for each of Categorical Variables with all the Continuous Variables.
Output --> List of Continuous Variables, whose pValue is < 0.05
"""
target = self.target
AnovaList = []
for ContinuousVar in self.ContinuousFeatures:
temp_df = self.df[[ContinuousVar, target]].dropna()
try:
f,p = stats.f_oneway(*[list(temp_df[temp_df[target]==name][ContinuousVar]) for name in set(temp_df[target])])
AnovaList.append(dict(Continuous = ContinuousVar, PValue = p))
except:
# Do nothing. Skip.
1==1
Anova_df = pd.DataFrame(AnovaList)
if Anova_df.shape[0]>0:
Anova_df = Anova_df[Anova_df['PValue']<=0.05]
Anova_df.sort_values(['PValue'],ascending = True, inplace=True)
return Anova_df
示例4: print_oneway
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import f_oneway [as 别名]
def print_oneway(X, genes, ds_labels):
for gene_idx, gene in enumerate(genes):
ds_names = sorted(set(ds_labels))
dist = []
for ds in ds_names:
dist.append(X[ds_labels == ds, gene_idx])
sys.stdout.write('{}\t'.format(gene))
print('{}\t{}'.format(*f_oneway(*dist)))
示例5: anova
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import f_oneway [as 别名]
def anova(_arg1, _arg2, *_argN):
"""
ANOVA is a statistical hypothesis test that is used to compare
two or more group means for equality.For more information on
the function and how to use it please refer to tabpy-tools.md
"""
cols = [_arg1, _arg2] + list(_argN)
for col in cols:
if not isinstance(col[0], (int, float)):
print("values must be numeric")
raise ValueError
_, p_value = stats.f_oneway(_arg1, _arg2, *_argN)
return p_value
示例6: test_trivial
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import f_oneway [as 别名]
def test_trivial(self):
# A trivial test of stats.f_oneway, with F=0.
F, p = stats.f_oneway([0,2], [0,2])
assert_equal(F, 0.0)
示例7: test_basic
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import f_oneway [as 别名]
def test_basic(self):
# A test of stats.f_oneway, with F=2.
F, p = stats.f_oneway([0,2], [2,4])
# Despite being a floating point calculation, this data should
# result in F being exactly 2.0.
assert_equal(F, 2.0)
示例8: test_f_oneway_vs_scipy_stats
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import f_oneway [as 别名]
def test_f_oneway_vs_scipy_stats():
# Test that our f_oneway gives the same result as scipy.stats
rng = np.random.RandomState(0)
X1 = rng.randn(10, 3)
X2 = 1 + rng.randn(10, 3)
f, pv = stats.f_oneway(X1, X2)
f2, pv2 = f_oneway(X1, X2)
assert np.allclose(f, f2)
assert np.allclose(pv, pv2)
示例9: test_f_oneway_ints
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import f_oneway [as 别名]
def test_f_oneway_ints():
# Smoke test f_oneway on integers: that it does raise casting errors
# with recent numpys
rng = np.random.RandomState(0)
X = rng.randint(10, size=(10, 10))
y = np.arange(10)
fint, pint = f_oneway(X, y)
# test that is gives the same result as with float
f, p = f_oneway(X.astype(np.float), y)
assert_array_almost_equal(f, fint, decimal=4)
assert_array_almost_equal(p, pint, decimal=4)
示例10: test_basic
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import f_oneway [as 别名]
def test_basic(self):
# Despite being a floating point calculation, this data should
# result in F being exactly 2.0.
F, p = stats.f_oneway([0,2], [2,4])
assert_equal(F, 2.0)
示例11: test_large_integer_array
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import f_oneway [as 别名]
def test_large_integer_array(self):
a = np.array([655, 788], dtype=np.uint16)
b = np.array([789, 772], dtype=np.uint16)
F, p = stats.f_oneway(a, b)
assert_almost_equal(F, 0.77450216931805538)
示例12: test_result_attributes
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import f_oneway [as 别名]
def test_result_attributes(self):
a = np.array([655, 788], dtype=np.uint16)
b = np.array([789, 772], dtype=np.uint16)
res = stats.f_oneway(a, b)
attributes = ('statistic', 'pvalue')
check_named_results(res, attributes)
示例13: test_nist
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import f_oneway [as 别名]
def test_nist(self):
# These are the nist ANOVA files. They can be found at:
# http://www.itl.nist.gov/div898/strd/anova/anova.html
filenames = ['SiRstv.dat', 'SmLs01.dat', 'SmLs02.dat', 'SmLs03.dat',
'AtmWtAg.dat', 'SmLs04.dat', 'SmLs05.dat', 'SmLs06.dat',
'SmLs07.dat', 'SmLs08.dat', 'SmLs09.dat']
for test_case in filenames:
rtol = 1e-7
fname = os.path.abspath(os.path.join(os.path.dirname(__file__),
'data/nist_anova', test_case))
with open(fname, 'r') as f:
content = f.read().split('\n')
certified = [line.split() for line in content[40:48]
if line.strip()]
dataf = np.loadtxt(fname, skiprows=60)
y, x = dataf.T
y = y.astype(int)
caty = np.unique(y)
f = float(certified[0][-1])
xlist = [x[y == i] for i in caty]
res = stats.f_oneway(*xlist)
# With the hard test cases we relax the tolerance a bit.
hard_tc = ('SmLs07.dat', 'SmLs08.dat', 'SmLs09.dat')
if test_case in hard_tc:
rtol = 1e-4
assert_allclose(res[0], f, rtol=rtol,
err_msg='Failing testcase: %s' % test_case)
示例14: feature_specifity
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import f_oneway [as 别名]
def feature_specifity(feature, ref, classes, figsize=(6,6), save=None):
"""
Calculate the feature specifity:
Input:
feature: latent feature
ref: cluster assignments
classes: cluster classes
"""
from scipy.stats import f_oneway
# n_cluster = max(ref) + 1
n_cluster = len(classes)
dim = feature.shape[1] # feature dimension
pvalue_mat = np.zeros((dim, n_cluster))
for i,cluster in enumerate(classes):
for feat in range(dim):
a = feature.iloc[:, feat][ref == cluster]
b = feature.iloc[:, feat][ref != cluster]
pvalue = f_oneway(a,b)[1]
pvalue_mat[feat, i] = pvalue
plt.figure(figsize=figsize)
grid = sns.heatmap(-np.log10(pvalue_mat), cmap='RdBu_r',
vmax=20,
yticklabels=np.arange(10)+1,
xticklabels=classes[:n_cluster],
)
grid.set_ylabel('Feature', fontsize=18)
grid.set_xticklabels(labels=classes[:n_cluster], rotation=45, fontsize=18)
grid.set_yticklabels(labels=np.arange(dim)+1, fontsize=16)
cbar = grid.collections[0].colorbar
cbar.set_label('-log10 (Pvalue)', fontsize=18) #, rotation=0, x=-0.9, y=0)
if save:
plt.savefig(save, format='pdf', bbox_inches='tight')
else:
plt.show()
示例15: anova
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import f_oneway [as 别名]
def anova(labels, results, subset_labels=None):
"""
Returns one-way ANOVA f-statistic and p-value from
input vectors of categorical labels and numeric results
Parameters
------------
labels : array_like
containing categorical values like ['M', 'F']
results : array_like
containing real numbers
subset_labels : list of strings, optional
if only specific labels should be included
Returns
----------
F_onewayResult : scipy.stats object (essentially a 2-tuple)
contains one-way f-statistic and p-value, indicating whether
scores have same sample mean
"""
check_consistent_length(labels, results)
df = pd.DataFrame(list(zip(labels, results)), columns=['label', 'result'])
if subset_labels is not None:
df = df.loc[df['label'].isin(subset_labels)]
unique_labels = df['label'].dropna().unique()
score_vectors = [df.loc[df['label'] == lab, 'result']
for lab in unique_labels]
return f_oneway(*score_vectors)