当前位置: 首页>>代码示例>>Python>>正文


Python stats.f_oneway方法代码示例

本文整理汇总了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]]) 
开发者ID:rmarkello,项目名称:abagen,代码行数:19,代码来源:test_correct.py

示例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 
开发者ID:exploripy,项目名称:exploripy,代码行数:25,代码来源:TargetAnalysisContinuous.py

示例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 
开发者ID:exploripy,项目名称:exploripy,代码行数:24,代码来源:TargetAnalysisCategorical.py

示例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))) 
开发者ID:brianhie,项目名称:scanorama,代码行数:10,代码来源:pancreas_tests.py

示例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 
开发者ID:tableau,项目名称:TabPy,代码行数:16,代码来源:ANOVA.py

示例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) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:6,代码来源:test_stats.py

示例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) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:8,代码来源:test_stats.py

示例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) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:11,代码来源:test_feature_select.py

示例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) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:14,代码来源:test_feature_select.py

示例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) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:7,代码来源:test_stats.py

示例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) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:7,代码来源:test_stats.py

示例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) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:8,代码来源:test_stats.py

示例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) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:33,代码来源:test_stats.py

示例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() 
开发者ID:jsxlei,项目名称:SCALE,代码行数:39,代码来源:plot.py

示例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) 
开发者ID:pymetrics,项目名称:audit-ai,代码行数:33,代码来源:misc.py


注:本文中的scipy.stats.f_oneway方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。