當前位置: 首頁>>代碼示例>>Python>>正文


Python stats.spearmanr方法代碼示例

本文整理匯總了Python中scipy.stats.spearmanr方法的典型用法代碼示例。如果您正苦於以下問題:Python stats.spearmanr方法的具體用法?Python stats.spearmanr怎麽用?Python stats.spearmanr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在scipy.stats的用法示例。


在下文中一共展示了stats.spearmanr方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: time_dist

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import spearmanr [as 別名]
def time_dist(datasets_dimred, time):
    time_dist = euclidean_distances(time, time)

    time_dists, scores = [], []
    for i in range(time_dist.shape[0]):
        for j in range(time_dist.shape[1]):
            if i >= j:
                continue
            score = np.mean(euclidean_distances(
                datasets_dimred[i], datasets_dimred[j]
            ))
            time_dists.append(time_dist[i, j])
            scores.append(score)

    print('Spearman rho = {}'.format(spearmanr(time_dists, scores)))
    print('Pearson rho = {}'.format(pearsonr(time_dists, scores))) 
開發者ID:brianhie,項目名稱:scanorama,代碼行數:18,代碼來源:time_align.py

示例2: evaluate

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import spearmanr [as 別名]
def evaluate(wv, reference):
    """Evaluate wv against reference, return (rho, count) where rwo is
    Spearman's rho and count is the number of reference word pairs
    that could be evaluated against.
    """
    gold, predicted = [], []
    for words, sim in sorted(reference, key=lambda ws: ws[1]):
        try:
            v1, v2 = wv[words[0]], wv[words[1]]
        except KeyError:
            continue
        gold.append((words, sim))
        predicted.append((words, cosine(v1, v2)))
    simlist = lambda ws: [s for w,s in ws]
    rho, p = spearmanr(simlist(gold), simlist(predicted))
    return (rho, len(gold)) 
開發者ID:cambridgeltl,項目名稱:link-prediction_with_deep-learning,代碼行數:18,代碼來源:evalrank.py

示例3: get_corr_func

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import spearmanr [as 別名]
def get_corr_func(method):
    if method in ['kendall', 'spearman']:
        from scipy.stats import kendalltau, spearmanr
    elif callable(method):
        return method

    def _pearson(a, b):
        return np.corrcoef(a, b)[0, 1]

    def _kendall(a, b):
        rs = kendalltau(a, b)
        if isinstance(rs, tuple):
            return rs[0]
        return rs

    def _spearman(a, b):
        return spearmanr(a, b)[0]

    _cor_methods = {
        'pearson': _pearson,
        'kendall': _kendall,
        'spearman': _spearman
    }
    return _cor_methods[method] 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:26,代碼來源:nanops.py

示例4: word_sim_test

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import spearmanr [as 別名]
def word_sim_test(filename, pos_vectors):
    delim = ','
    actual_sim_list, pred_sim_list = [], []
    missed = 0

    with open(filename, 'r') as pairs:
        for pair in pairs:
            w1, w2, actual_sim = pair.strip().split(delim)

            try:
                w1_vec = create_word_vector(w1, pos_vectors)
                w2_vec = create_word_vector(w2, pos_vectors)
                pred = float(np.inner(w1_vec, w2_vec))
                actual_sim_list.append(float(actual_sim))
                pred_sim_list.append(pred)

            except KeyError:
                missed += 1

    spearman, _ = st.spearmanr(actual_sim_list, pred_sim_list)
    pearson, _ = st.pearsonr(actual_sim_list, pred_sim_list)

    return spearman, pearson, missed 
開發者ID:dongjun-Lee,項目名稱:kor2vec,代碼行數:25,代碼來源:similarity_test.py

示例5: feature_corr_matrix

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import spearmanr [as 別名]
def feature_corr_matrix(df):
    """
    Return the Spearman's rank-order correlation between all pairs
    of features as a matrix with feature names as index and column names.
    The diagonal will be all 1.0 as features are self correlated.

    Spearman's correlation is the same thing as converting two variables
    to rank values and then running a standard Pearson's correlation
    on those ranked variables. Spearman's is nonparametric and does not
    assume a linear relationship between the variables; it looks for
    monotonic relationships.

    :param df_train: dataframe containing features as columns, and
                     without the target variable.
    :return: a data frame with the correlation matrix
    """
    corr = np.round(spearmanr(df).correlation, 4)
    df_corr = pd.DataFrame(data=corr, index=df.columns, columns=df.columns)
    return df_corr 
開發者ID:canard0328,項目名稱:malss,代碼行數:21,代碼來源:rfpimp.py

示例6: spearmanr

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import spearmanr [as 別名]
def spearmanr(self):
    """ Compute target SpearmanR vector. """

    scor = np.zeros(self.num_targets)

    for ti in range(self.num_targets):
      if self.targets_na is not None:
        preds_ti = self.preds[~self.targets_na, ti]
        targets_ti = self.targets[~self.targets_na, ti]
      else:
        preds_ti = self.preds[:, :, ti].flatten()
        targets_ti = self.targets[:, :, ti].flatten()

      sc, _ = stats.spearmanr(targets_ti, preds_ti)
      scor[ti] = sc

    return scor


################################################################################
# __main__
################################################################################ 
開發者ID:calico,項目名稱:basenji,代碼行數:24,代碼來源:accuracy.py

示例7: imputation_score

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import spearmanr [as 別名]
def imputation_score(trainer_both, data_spatial, gene_ids_test, normalized=True):
    _, fish_imputation = trainer_both.get_imputed_values(normalized=normalized)
    original, imputed = (
        data_spatial.X[:, gene_ids_test],
        fish_imputation[:, gene_ids_test],
    )

    if normalized:
        original /= data_spatial.X.sum(axis=1).reshape(-1, 1)

    spearman_gene = []
    for g in range(imputed.shape[1]):
        if np.all(imputed[:, g] == 0):
            correlation = 0
        else:
            correlation = spearmanr(original[:, g], imputed[:, g])[0]
        spearman_gene.append(correlation)
    return np.median(np.array(spearman_gene)) 
開發者ID:YosefLab,項目名稱:scVI,代碼行數:20,代碼來源:gimvi_tutorial.py

示例8: eval_per_query

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import spearmanr [as 別名]
def eval_per_query(self, y, y_pred):
        """
        This methods computes Spearman Rho at per query level (on the instances
        belonging to a specific query).

        Parameters
        ----------
        y: numpy array
            Represents the labels of instances corresponding to one query in the
            dataset (ground truth).
        y_pred: numpy array.
            Represents the predicted document scores obtained during the model
            scoring phase for that query.

        Returns
        -------
        rho: float
            The Spearman Rho per query.
        """
        spearman_rho = stats.spearmanr(y, y_pred)
        return spearman_rho.correlation 
開發者ID:hpclab,項目名稱:rankeval,代碼行數:23,代碼來源:spearman_rho.py

示例9: get_corr_func

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import spearmanr [as 別名]
def get_corr_func(method):
    if method in ['kendall', 'spearman']:
        from scipy.stats import kendalltau, spearmanr

    def _pearson(a, b):
        return np.corrcoef(a, b)[0, 1]

    def _kendall(a, b):
        rs = kendalltau(a, b)
        if isinstance(rs, tuple):
            return rs[0]
        return rs

    def _spearman(a, b):
        return spearmanr(a, b)[0]

    _cor_methods = {
        'pearson': _pearson,
        'kendall': _kendall,
        'spearman': _spearman
    }
    return _cor_methods[method] 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:24,代碼來源:nanops.py

示例10: test_tie1

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import spearmanr [as 別名]
def test_tie1(self):
        # Data
        x = [1.0, 2.0, 3.0, 4.0]
        y = [1.0, 2.0, 2.0, 3.0]
        # Ranks of the data, with tie-handling.
        xr = [1.0, 2.0, 3.0, 4.0]
        yr = [1.0, 2.5, 2.5, 4.0]
        # Result of spearmanr should be the same as applying
        # pearsonr to the ranks.
        sr = stats.spearmanr(x, y)
        pr = stats.pearsonr(xr, yr)
        assert_almost_equal(sr, pr)


##    W.II.E.  Tabulate X against X, using BIG as a case weight.  The values
##    should appear on the diagonal and the total should be 899999955.
##    If the table cannot hold these values, forget about working with
##    census data.  You can also tabulate HUGE against TINY.  There is no
##    reason a tabulation program should not be able to distinguish
##    different values regardless of their magnitude.

### I need to figure out how to do this one. 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:24,代碼來源:test_stats.py

示例11: __call__

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import spearmanr [as 別名]
def __call__(self):
        all_results = np.empty((len(self.systems), len(self.measures)))
        # TODO: parallelise?
        for system, sys_results in zip(self.systems, all_results):
            if self.gold is None:
                result_dict = Evaluate.read_tab_format(utf8_open(system))
            else:
                result_dict = Evaluate(system, self.gold, measures=self.measures, fmt='none')()
            sys_results[...] = [result_dict[measure]['fscore'] for measure in self.measures]

        self.all_results = all_results

        correlations = {}
        scores_by_measure = zip(self.measures, all_results.T)
        for (measure_i, scores_i), (measure_j, scores_j) in _pairs(scores_by_measure):
            correlations[measure_i, measure_j] = {'pearson': stats.pearsonr(scores_i, scores_j),
                                                  'spearman': stats.spearmanr(scores_i, scores_j),
                                                  'kendall': stats.kendalltau(scores_i, scores_j)}

        quartiles = {}
        for measure_i, scores_i in scores_by_measure:
            quartiles[measure_i] = np.percentile(scores_i, [0, 25, 50, 75, 100])

        return self.format(self, {'quartiles': quartiles, 'correlations': correlations}) 
開發者ID:wikilinks,項目名稱:neleval,代碼行數:26,代碼來源:summary.py

示例12: pearson_and_spearman

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import spearmanr [as 別名]
def pearson_and_spearman(preds, labels):
        pearson_corr = pearsonr(preds, labels)[0]
        spearman_corr = spearmanr(preds, labels)[0]
        return {
            "pearson": pearson_corr,
            "spearmanr": spearman_corr,
            "corr": (pearson_corr + spearman_corr) / 2,
        } 
開發者ID:microsoft,項目名稱:botbuilder-python,代碼行數:10,代碼來源:bert_util.py

示例13: time_align_correlate

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import spearmanr [as 別名]
def time_align_correlate(alignments, time):
    time_dist = euclidean_distances(time, time)

    assert(time_dist.shape == alignments.shape)

    time_dists, scores = [], []
    for i in range(time_dist.shape[0]):
        for j in range(time_dist.shape[1]):
            if i >= j:
                continue
            time_dists.append(time_dist[i, j])
            scores.append(alignments[i, j])

    print('Spearman rho = {}'.format(spearmanr(time_dists, scores)))
    print('Pearson rho = {}'.format(pearsonr(time_dists, scores))) 
開發者ID:brianhie,項目名稱:scanorama,代碼行數:17,代碼來源:time_align.py

示例14: validate_spearman_correlation

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import spearmanr [as 別名]
def validate_spearman_correlation(overall_imp, shap_overall_imp, threshold):
    # Calculate the spearman rank-order correlation
    rho, p_val = stats.spearmanr(overall_imp, shap_overall_imp)
    # Validate that the coefficients from the linear model are highly correlated with the results from shap
    test_logger.info(
        "Calculated spearman correlation coefficient rho: "
        + str(rho)
        + " and p_val: "
        + str(p_val)
    )
    assert rho > threshold 
開發者ID:interpretml,項目名稱:interpret-text,代碼行數:13,代碼來源:test_validate_explanations.py

示例15: test_fit

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import spearmanr [as 別名]
def test_fit(self):
        np.random.seed(1)
        tf.reset_default_graph()
        tf.set_random_seed(0)
        latent_dim = 2
        res_ranks, res_biplot = paired_omics(
            self.microbes, self.metabolites,
            epochs=1000, latent_dim=latent_dim,
            min_feature_count=1, learning_rate=0.1
        )
        res_ranks = clr_inv(res_ranks.T)
        s_r, s_p = spearmanr(np.ravel(res_ranks), np.ravel(self.exp_ranks))

        self.assertGreater(s_r, 0.5)
        self.assertLess(s_p, 1e-2)

        # make sure the biplot is of the correct dimensions
        npt.assert_allclose(
            res_biplot.samples.shape,
            np.array([self.microbes.shape[0], latent_dim]))
        npt.assert_allclose(
            res_biplot.features.shape,
            np.array([self.metabolites.shape[0], latent_dim]))

        # make sure that the biplot has the correct ordering
        self.assertGreater(res_biplot.proportion_explained[0],
                           res_biplot.proportion_explained[1])
        self.assertGreater(res_biplot.eigvals[0],
                           res_biplot.eigvals[1]) 
開發者ID:biocore,項目名稱:mmvec,代碼行數:31,代碼來源:test_method.py


注:本文中的scipy.stats.spearmanr方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。