本文整理汇总了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)
示例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()
示例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())
示例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)
示例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
示例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))
示例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)
示例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)
示例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)
示例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))
示例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]
示例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
示例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)
示例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)
示例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()