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


Python stats.hmean方法代码示例

本文整理汇总了Python中scipy.stats.hmean方法的典型用法代码示例。如果您正苦于以下问题:Python stats.hmean方法的具体用法?Python stats.hmean怎么用?Python stats.hmean使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scipy.stats的用法示例。


在下文中一共展示了stats.hmean方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _computer_harmoic_mean_of_probabilities_over_non_zero_in_category_count_terms

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import hmean [as 别名]
def _computer_harmoic_mean_of_probabilities_over_non_zero_in_category_count_terms(self,
                                                                                      cat_word_counts,
                                                                                      p_category_given_word,
                                                                                      p_word_given_category,
                                                                                      scaler):
        df = pd.DataFrame({
            'cat_word_counts': cat_word_counts,
            'p_word_given_category': p_word_given_category,
            'p_category_given_word': p_category_given_word
        })
        df_with_count = df[df['cat_word_counts'] > 0]
        df_with_count['scale p_word_given_category'] = scaler(df_with_count['p_word_given_category'])
        df_with_count['scale p_category_given_word'] = scaler(df_with_count['p_category_given_word'])
        df['scale p_word_given_category'] = 0
        df.loc[df_with_count.index, 'scale p_word_given_category'] = df_with_count['scale p_word_given_category']
        df['scale p_category_given_word'] = 0
        df.loc[df_with_count.index, 'scale p_category_given_word'] \
            = df_with_count['scale p_category_given_word']
        score = hmean([df_with_count['scale p_category_given_word'],
                       df_with_count['scale p_word_given_category']])
        df['score'] = 0
        df.loc[df_with_count.index, 'score'] = score
        return df['score'] 
开发者ID:JasonKessler,项目名称:scattertext,代码行数:25,代码来源:TermDocMatrix.py

示例2: computeF1_macro

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import hmean [as 别名]
def computeF1_macro(confusion_matrix,matching, num_clusters):
	"""
	computes the macro F1 score
	confusion matrix : requres permutation
	matching according to which matrix must be permuted
	"""
	##Permute the matrix columns
	permuted_confusion_matrix = np.zeros([num_clusters,num_clusters])
	for cluster in xrange(num_clusters):
		matched_cluster = matching[cluster]
 		permuted_confusion_matrix[:,cluster] = confusion_matrix[:,matched_cluster]
 	##Compute the F1 score for every cluster
 	F1_score = 0
 	for cluster in xrange(num_clusters):
 		TP = permuted_confusion_matrix[cluster,cluster]
 		FP = np.sum(permuted_confusion_matrix[:,cluster]) - TP
 		FN = np.sum(permuted_confusion_matrix[cluster,:]) - TP
 		precision = TP/(TP + FP)
 		recall = TP/(TP + FN)
 		f1 = stats.hmean([precision,recall])
 		F1_score += f1
 	F1_score /= num_clusters
 	return F1_score 
开发者ID:davidhallac,项目名称:TICC,代码行数:25,代码来源:TICC.py

示例3: test_1D_list

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import hmean [as 别名]
def test_1D_list(self):
        a = (1,2,3,4)
        actual = stats.hmean(a)
        desired = 4. / (1./1 + 1./2 + 1./3 + 1./4)
        assert_almost_equal(actual, desired, decimal=14)

        desired1 = stats.hmean(array(a),axis=-1)
        assert_almost_equal(actual, desired1, decimal=14) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:10,代码来源:test_stats.py

示例4: test_1D_array

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import hmean [as 别名]
def test_1D_array(self):
        a = array((1,2,3,4), float64)
        actual = stats.hmean(a)
        desired = 4. / (1./1 + 1./2 + 1./3 + 1./4)
        assert_almost_equal(actual, desired, decimal=14)

        desired1 = stats.hmean(a,axis=-1)
        assert_almost_equal(actual, desired1, decimal=14) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:10,代码来源:test_stats.py

示例5: test_2D_array_default

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import hmean [as 别名]
def test_2D_array_default(self):
        a = array(((1,2,3,4),
                   (1,2,3,4),
                   (1,2,3,4)))
        actual = stats.hmean(a)
        desired = array((1.,2.,3.,4.))
        assert_array_almost_equal(actual, desired, decimal=14)

        actual1 = stats.hmean(a,axis=0)
        assert_array_almost_equal(actual1, desired, decimal=14) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:12,代码来源:test_stats.py

示例6: test_2D_array_dim1

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import hmean [as 别名]
def test_2D_array_dim1(self):
        a = array(((1,2,3,4),
                   (1,2,3,4),
                   (1,2,3,4)))

        v = 4. / (1./1 + 1./2 + 1./3 + 1./4)
        desired1 = array((v,v,v))
        actual1 = stats.hmean(a, axis=1)
        assert_array_almost_equal(actual1, desired1, decimal=14) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:11,代码来源:test_stats.py

示例7: do

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import hmean [as 别名]
def do(self, a, b, axis=None, dtype=None):
        x = stats.hmean(a, axis=axis, dtype=dtype)
        assert_almost_equal(b, x)
        assert_equal(x.dtype, dtype) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:6,代码来源:test_stats.py

示例8: test_1D

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import hmean [as 别名]
def test_1D(self):
        a = (1,2,3,4)
        actual = mstats.hmean(a)
        desired = 4. / (1./1 + 1./2 + 1./3 + 1./4)
        assert_almost_equal(actual, desired, decimal=14)
        desired1 = mstats.hmean(ma.array(a),axis=-1)
        assert_almost_equal(actual, desired1, decimal=14)

        a = ma.array((1,2,3,4),mask=(0,0,0,1))
        actual = mstats.hmean(a)
        desired = 3. / (1./1 + 1./2 + 1./3)
        assert_almost_equal(actual, desired,decimal=14)
        desired1 = mstats.hmean(a,axis=-1)
        assert_almost_equal(actual, desired1, decimal=14) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:16,代码来源:test_mstats_basic.py

示例9: test_1D_float96

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import hmean [as 别名]
def test_1D_float96(self):
        a = ma.array((1,2,3,4), mask=(0,0,0,1))
        actual_dt = mstats.hmean(a, dtype=np.float96)
        desired_dt = np.asarray(3. / (1./1 + 1./2 + 1./3),
                                dtype=np.float96)
        assert_almost_equal(actual_dt, desired_dt, decimal=14)
        assert_(actual_dt.dtype == desired_dt.dtype) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:9,代码来源:test_mstats_basic.py

示例10: test_2D

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import hmean [as 别名]
def test_2D(self):
        a = ma.array(((1,2,3,4),(1,2,3,4),(1,2,3,4)),
                     mask=((0,0,0,0),(1,0,0,1),(0,1,1,0)))
        actual = mstats.hmean(a)
        desired = ma.array((1,2,3,4))
        assert_array_almost_equal(actual, desired, decimal=14)

        actual1 = mstats.hmean(a,axis=-1)
        desired = (4./(1/1.+1/2.+1/3.+1/4.),
                   2./(1/2.+1/3.),
                   2./(1/1.+1/4.)
                   )
        assert_array_almost_equal(actual1, desired, decimal=14) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:15,代码来源:test_mstats_basic.py

示例11: test_hmean

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import hmean [as 别名]
def test_hmean(self):
        for n in self.get_n():
            x, y, xm, ym = self.generate_xy_sample(n)

            r = stats.hmean(abs(x))
            rm = stats.mstats.hmean(abs(xm))
            assert_almost_equal(r, rm, 10)

            r = stats.hmean(abs(y))
            rm = stats.mstats.hmean(abs(ym))
            assert_almost_equal(r, rm, 10) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:13,代码来源:test_mstats_basic.py

示例12: all_features

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import hmean [as 别名]
def all_features():
    """ Returns dictionary of all features in the module

    .. note:: Some of the features (hist4, corr) are relatively expensive to compute
    """
    features = {'mean': mean,
                'median': median,
                'gmean': gmean,
                'hmean': hmean,
                'vec_sum': vec_sum,
                'abs_sum': abs_sum,
                'abs_energy': abs_energy,
                'std': std,
                'var': var,
                'mad': median_absolute_deviation,
                'variation': variation,
                'min': minimum,
                'max': maximum,
                'skew': skew,
                'kurt': kurt,
                'mean_diff': mean_diff,
                'mean_abs_diff': means_abs_diff,
                'mse': mse,
                'mnx': mean_crossings,
                'hist4': hist(),
                'corr': corr2,
                'mean_abs_value': mean_abs,
                'zero_crossings': zero_crossing(),
                'slope_sign_changes': slope_sign_changes(),
                'waveform_length': waveform_length,
                'emg_var': emg_var,
                'root_mean_square': root_mean_square,
                'willison_amplitude': willison_amplitude()}
    return features 
开发者ID:dmbee,项目名称:seglearn,代码行数:36,代码来源:feature_functions.py

示例13: hmean

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import hmean [as 别名]
def hmean(X):
    """ harmonic mean for each variable """
    return stats.hmean(X, axis=1) 
开发者ID:dmbee,项目名称:seglearn,代码行数:5,代码来源:feature_functions.py

示例14: computeF1_macro

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import hmean [as 别名]
def computeF1_macro(confusion_matrix,matching, num_clusters):
	"""
	computes the macro F1 score
	confusion matrix : requres permutation
	matching according to which matrix must be permuted
	"""
	##Permute the matrix columns
	permuted_confusion_matrix = np.zeros([num_clusters,num_clusters])
	for cluster in xrange(num_clusters):
		matched_cluster = matching[cluster]
 		permuted_confusion_matrix[:,cluster] = confusion_matrix[:,matched_cluster]
 	##Compute the F1 score for every cluster
 	F1_score = 0
 	for cluster in xrange(num_clusters):
 		TP = permuted_confusion_matrix[cluster,cluster]
 		FP = np.sum(permuted_confusion_matrix[:,cluster]) - TP
 		FN = np.sum(permuted_confusion_matrix[cluster,:]) - TP
 		precision = TP/(TP + FP)
 		recall = TP/(TP + FN)
 		f1 = stats.hmean([precision,recall])
 		F1_score += f1
 	F1_score /= num_clusters
 	return F1_score

############
##The basic folder to be created 
开发者ID:davidhallac,项目名称:TICC,代码行数:28,代码来源:scalability_test.py

示例15: create_modeling_tables

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import hmean [as 别名]
def create_modeling_tables(spi_historical, spi_fixtures, fd_historical, fd_fixtures, names_mapping):
    """Create tables for machine learning modeling."""

    # Rename teams
    for col in ['team1', 'team2']:
        spi_historical = pd.merge(spi_historical, names_mapping, left_on=col, right_on='left_team', how='left').drop(columns=[col, 'left_team']).rename(columns={'right_team': col})
        spi_fixtures = pd.merge(spi_fixtures, names_mapping, left_on=col, right_on='left_team', how='left').drop(columns=[col, 'left_team']).rename(columns={'right_team': col})

    # Combine data
    historical = pd.merge(spi_historical, fd_historical, left_on=SPI_KEYS, right_on=FD_KEYS).dropna(subset=ODDS_COLS_MAPPING.keys(), how='any').reset_index(drop=True)
    fixtures = pd.merge(spi_fixtures, fd_fixtures, left_on=SPI_KEYS, right_on=FD_KEYS)

    # Extract training, odds and fixtures
    X = historical.loc[:, ['season'] + SPI_KEYS + INPUT_COLS]
    y = historical.loc[:, OUTPUT_COLS]
    odds = historical.loc[:, SPI_KEYS + list(ODDS_COLS_MAPPING.keys())].rename(columns=ODDS_COLS_MAPPING)
    X_test = fixtures.loc[:, SPI_KEYS + INPUT_COLS]
    odds_test = fixtures.loc[:, SPI_KEYS + list(ODDS_COLS_MAPPING.keys())].rename(columns=ODDS_COLS_MAPPING)

    # Add average scores columns
    for ind in (1, 2):
        avg_score =  y[['adj_score%s' % ind, 'xg%s' % ind, 'nsxg%s' % ind]].mean(axis=1)
        avg_score[avg_score.isna()] = y['score%s' % ind]
        y['avg_score%s' % ind] = avg_score

    # Add combined odds columns
    for target in TARGETS:
        if '+' in target:
            targets = target.split('+')
            odds[target] = combine_odds(odds[targets])
            odds_test[target] = combine_odds(odds_test[targets])

    # Feature extraction
    with np.errstate(divide='ignore', invalid='ignore'):
        for df in (X, X_test):
            df['quality'] = hmean(df[['spi1', 'spi2']], axis=1)
            df['importance'] = df[['importance1', 'importance2']].mean(axis=1)
            df['rating'] = df[['quality', 'importance']].mean(axis=1)
            df['sum_proj_score'] = df['proj_score1'] + df['proj_score2']
    
    return X, y, odds, X_test, odds_test 
开发者ID:AlgoWit,项目名称:sports-betting,代码行数:43,代码来源:data.py


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