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


Python stats.pearsonr方法代碼示例

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


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

示例1: calc_r

# 需要導入模塊: from scipy.stats import stats [as 別名]
# 或者: from scipy.stats.stats import pearsonr [as 別名]
def calc_r(obs, sim):
    """Calculate the pearson r coefficient.
    
    Interface to the scipy implementation of the pearson r coeffienct.
    
    Args:
        obs: Array of the observed values
        sim: Array of the simulated values

    Returns:
        The pearson r coefficient of the simulation compared to the observation.
 
    """
    # Validation check on the input arrays
    obs = validate_array_input(obs, np.float64, 'obs')
    sim = validate_array_input(sim, np.float64, 'sim')
    
    if len(obs) != len(sim):
        raise ValueError("Arrays must have the same size.")
    
    return pearsonr(obs, sim) 
開發者ID:kratzert,項目名稱:RRMPG,代碼行數:23,代碼來源:metrics.py

示例2: __plot_closest_neighbours__

# 需要導入模塊: from scipy.stats import stats [as 別名]
# 或者: from scipy.stats.stats import pearsonr [as 別名]
def __plot_closest_neighbours__(self,zooniverse_id_list):
        totalY = []
        totalDist = []

        for zooniverse_id in zooniverse_id_list:
            if zooniverse_id in self.closet_neighbours:
                pt_l,dist_l = zip(*self.closet_neighbours[zooniverse_id])
                X_pts,Y_pts = zip(*pt_l)

                # find to flip the image
                Y_pts = [-p for p in Y_pts]

                plt.plot(dist_l,Y_pts,'.',color="red")

                totalDist.extend(dist_l)
                totalY.extend(Y_pts)

        print pearsonr(dist_l,Y_pts)
        plt.show() 
開發者ID:zooniverse,項目名稱:aggregation,代碼行數:21,代碼來源:aggregation.py

示例3: uncorrelatedVariable

# 需要導入模塊: from scipy.stats import stats [as 別名]
# 或者: from scipy.stats.stats import pearsonr [as 別名]
def uncorrelatedVariable(data):
    """
    用不相關的x1,x2搭建回歸模型
    """
    # 在Windows下運行此腳本需確保Windows下的命令提示符(cmd)能顯示中文
    print("x1和x2的相關係數為:%s" % scss.pearsonr(data["x1"], data["x2"])[0])
    Y = data["y"]
    X = sm.add_constant(data["x1"])
    re = trainModel(X, Y)
    print(re.summary())
    X1 = sm.add_constant(data["x2"])
    re1 = trainModel(X1, Y)
    print(re1.summary())
    X2 = sm.add_constant(data[["x1", "x2"]])
    re2 = trainModel(X2, Y)
    print(re2.summary()) 
開發者ID:GenTang,項目名稱:intro_ds,代碼行數:18,代碼來源:multicollinearity.py

示例4: correlatedVariable

# 需要導入模塊: from scipy.stats import stats [as 別名]
# 或者: from scipy.stats.stats import pearsonr [as 別名]
def correlatedVariable(data):
    """
    用強相關的x1,x3搭建模型
    """
    print("x1和x3的相關係數為:%s" % scss.pearsonr(data["x1"], data["x3"])[0])
    Y = data["y"]
    X = sm.add_constant(data["x1"])
    re = trainModel(X, Y)
    print(re.summary())
    X1 = sm.add_constant(data["x3"])
    re1 = trainModel(X1, Y)
    print(re1.summary())
    X2 = sm.add_constant(data[["x1", "x3"]])
    re2 = trainModel(X2, Y)
    print(re2.summary())
    # 檢測多重共線性
    print("檢測假設x1和x3同時不顯著:")
    print(re2.f_test(["x1=0", "x3=0"]))
    vif = pd.DataFrame()
    vif["VIF Factor"] = [variance_inflation_factor(X2.values, i) for i in range(X2.shape[1])]
    vif["features"] = X2.columns
    print(vif) 
開發者ID:GenTang,項目名稱:intro_ds,代碼行數:24,代碼來源:multicollinearity.py

示例5: evaluation

# 需要導入模塊: from scipy.stats import stats [as 別名]
# 或者: from scipy.stats.stats import pearsonr [as 別名]
def evaluation(y_pred, y_true, th):
    # print(y_pred)
    # print(y_true)
    # print(pearsonr(np.ravel(y_pred), y_true))
    corr = pearsonr(np.ravel(y_pred), y_true)[0]
    # mse = np.square(np.subtract(y_pred, y_true)).mean()
    msetotal = mse_at_k(y_pred, y_true, 1.0)
    mse1 = mse_at_k(y_pred, y_true, 0.01)
    mse2 = mse_at_k(y_pred, y_true, 0.02)
    mse5 = mse_at_k(y_pred, y_true, 0.05)

    auroc = float('nan')
    if len([x for x in y_true if x > th]) > 0:
        auroc = roc_auc_score([1 if x > th else 0 for x in y_true], y_pred)
    precision1 = precision_at_k(y_pred, y_true, 0.01, th)
    precision2 = precision_at_k(y_pred, y_true, 0.02, th)
    precision5 = precision_at_k(y_pred, y_true, 0.05, th)
    precision10 = precision_at_k(y_pred, y_true, 0.1, th)
    #print(auroc, precision1, precision2, precision5)
    return (corr, msetotal, mse1, mse2, mse5, auroc, precision1, precision2, precision5, precision10)

# Outputs response embeddings for a given dictionary 
開發者ID:dmis-lab,項目名稱:KitcheNette,代碼行數:24,代碼來源:run.py

示例6: sum_corr

# 需要導入模塊: from scipy.stats import stats [as 別名]
# 或者: from scipy.stats.stats import pearsonr [as 別名]
def sum_corr(view1,view2,flag=''):
    
    print("test correlation")
    corr = 0
    for i,j in zip(view1,view2):
        corr += measures.pearsonr(i,j)[0]
    print('avg sum corr ::',flag,'::',corr/len(view1)) 
開發者ID:GauravBh1010tt,項目名稱:DeepLearn,代碼行數:9,代碼來源:utility.py

示例7: cal_sim

# 需要導入模塊: from scipy.stats import stats [as 別名]
# 或者: from scipy.stats.stats import pearsonr [as 別名]
def cal_sim(model,ind1,ind2=1999):
    view1 = np.load("test_v1.npy")[0:ind1]
    view2 = np.load("test_v2.npy")[0:ind2]
    label1 = np.load('test_l.npy')
    x1 = project(model,[view1,np.zeros_like(view1)])
    x2 = project(model,[np.zeros_like(view2),view2])
    label2 = []
    count = 0
    MAP=0
    for i,j in enumerate(x1):
        cor = []
        AP=0
        for y in x2:
            temp1 = j.tolist()
            temp2 = y.tolist()
            cor.append(pearsonr(temp1,temp2))
        #if i == np.argmax(cor):
        #    count+=1
        #val=[(q,(i*ind1+p))for p,q in enumerate(cor)]
        val=[(q,p)for p,q in enumerate(cor)]
        val.sort()
        val.reverse()
        label2.append(val[0:4])
        t = [w[1]for w in val[0:7]]
        #print t
        for x,y in enumerate(t):
            if y in range(i,i+5):
                AP+=1/(x+1)
        print(t)
        print(AP)
        MAP+=AP
    #print 'accuracy  :- ',float(count)*100/ind1,'%'
    print('MAP is : ',MAP/ind1) 
開發者ID:GauravBh1010tt,項目名稱:DeepLearn,代碼行數:35,代碼來源:utility.py

示例8: summarize

# 需要導入模塊: from scipy.stats import stats [as 別名]
# 或者: from scipy.stats.stats import pearsonr [as 別名]
def summarize(self):
        pearson = pearsonr(self.predictions, self.target)[0]
        summary = {self.metric_name: pearson}
        return self._prefix_keys(summary) 
開發者ID:Unbabel,項目名稱:OpenKiwi,代碼行數:6,代碼來源:metrics.py

示例9: score_sentence_level

# 需要導入模塊: from scipy.stats import stats [as 別名]
# 或者: from scipy.stats.stats import pearsonr [as 別名]
def score_sentence_level(gold, pred):
    pearson = pearsonr(gold, pred)
    mae = mean_absolute_error(gold, pred)
    rmse = np.sqrt(mean_squared_error(gold, pred))

    spearman = spearmanr(
        rankdata(gold, method="ordinal"), rankdata(pred, method="ordinal")
    )
    delta_avg = delta_average(gold, rankdata(pred, method="ordinal"))

    return (pearson[0], mae, rmse), (spearman[0], delta_avg) 
開發者ID:Unbabel,項目名稱:OpenKiwi,代碼行數:13,代碼來源:evaluate.py

示例10: cor_analysis

# 需要導入模塊: from scipy.stats import stats [as 別名]
# 或者: from scipy.stats.stats import pearsonr [as 別名]
def cor_analysis(co_price, pcb_price):
    """
    銅價和PCB價格相關性分析 
    """
    cor_draw(co_price, pcb_price)
    print(pearsonr(co_price.values, pcb_price.values)) 
開發者ID:liyinwei,項目名稱:copper_price_forecast,代碼行數:8,代碼來源:correlation_analysis.py

示例11: get_corr

# 需要導入模塊: from scipy.stats import stats [as 別名]
# 或者: from scipy.stats.stats import pearsonr [as 別名]
def get_corr(reduced, alldims):
    return pearsonr(alldims.ravel(), reduced.ravel())[0] 
開發者ID:ContextLab,項目名稱:hypertools,代碼行數:4,代碼來源:describe.py

示例12: wedge_mask_cor

# 需要導入模塊: from scipy.stats import stats [as 別名]
# 或者: from scipy.stats.stats import pearsonr [as 別名]
def wedge_mask_cor(v_abs, ops):

    for op in ops:
        m = tilt_mask(size=v_abs.shape, tilt_ang1=op['ang1'], tilt_ang2=op['ang2'], tilt_axis=op['tilt_axis'],
                            light_axis=op['light_axis'])
        # m = TIVWU.wedge_mask(size=v_abs.shape, ang1=op['ang1'], ang2=op['ang2'], tilt_axis=op['direction'])
        m = m.astype(N.float)

        op['cor'] = float(pearsonr(v_abs.flatten(), m.flatten())[0])

    return ops 
開發者ID:xulabs,項目名稱:aitom,代碼行數:13,代碼來源:tilt_angle_estimation.py

示例13: compare

# 需要導入模塊: from scipy.stats import stats [as 別名]
# 或者: from scipy.stats.stats import pearsonr [as 別名]
def compare(self):
        sims = [self.machine_sims[pair] for pair in self.sorted_word_pairs]
        vec_sims = [self.vec_sims[pair] for pair in self.sorted_word_pairs]

        pearson = pearsonr(sims, vec_sims)
        print "compared {0} distance pairs.".format(len(sims))
        print "Pearson-correlation: {0}".format(pearson) 
開發者ID:kornai,項目名稱:4lang,代碼行數:9,代碼來源:similarity.py

示例14: main_word_test

# 需要導入模塊: from scipy.stats import stats [as 別名]
# 或者: from scipy.stats.stats import pearsonr [as 別名]
def main_word_test(cfg):
    from scipy.stats.stats import pearsonr
    word_sim = WordSimilarity(cfg)
    out_dir = cfg.get('word_sim', 'out_dir')
    result_str = 'word1\tword2\tgold\tsim\tdiff\n'

    # TODO: only testing
    # machine = word_sim.lexicon.get_machine('merry-go-round')
    # links, nodes = word_sim.get_links_nodes(machine)
    # machine1 = word_sim.text_to_4lang.process_phrase('federal assembly')
    # nodes1 = word_sim.get_nodes_from_text_machine(machine1)

    test_pairs = get_test_pairs(cfg.get('sim', 'word_test_data'))
    sims, gold_sims = [], []
    for (w1, w2), gold_sim in test_pairs.iteritems():
        sim = word_sim.word_similarities(w1, w2)  # dummy POS-tags
        if sim is None:
            continue
        sim = sim.itervalues().next()
        gold_sims.append(gold_sim)
        sims.append(sim)
        result_str += "{0}\t{1}\t{2}\t{3}\t{4}".format(
            w1, w2, gold_sim, sim, math.fabs(sim - gold_sim)) + "\n"

    print "NO path exist: {0}".format(word_sim.sim_feats.no_path_cnt)
    print "Pearson: {0}".format(pearsonr(gold_sims, sims))
    print_results(out_dir, result_str) 
開發者ID:kornai,項目名稱:4lang,代碼行數:29,代碼來源:similarity.py

示例15: __plot_cluster_size__

# 需要導入模塊: from scipy.stats import stats [as 別名]
# 或者: from scipy.stats.stats import pearsonr [as 別名]
def __plot_cluster_size__(self,zooniverse_id_list):
        data = {}

        for zooniverse_id in zooniverse_id_list:
            if self.clusterResults[zooniverse_id] is not None:
                centers,pts,users = self.clusterResults[zooniverse_id]

                Y = [700-c[1] for c in centers]
                X = [len(p) for p in pts]

                plt.plot(X,Y,'.',color="blue")

                for x,y in zip(X,Y):
                    if not(x in data):
                        data[x] = [y]
                    else:
                        data[x].append(y)

        print pearsonr(X,Y)

        X = sorted(data.keys())
        Y = [np.mean(data[x]) for x in X]
        plt.plot(X,Y,'o-')
        plt.xlabel("Cluster Size")
        plt.ylabel("Height in Y-Pixels")
        plt.show() 
開發者ID:zooniverse,項目名稱:aggregation,代碼行數:28,代碼來源:aggregation.py


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