python计算相关系数
2016-10-25 12:09
351 查看
代码包括以下步骤:
从文件读数据
将list转化为ndarray
计算相关系数
import numpy as np
path = '/home/fhqplzj/IdeaProjects/DocumentClustering/FirstPython/bishe/data.txt'
file = open(path)
def fun(s):
return float(s.strip())
data = list(map(fun, file.readlines()))
x = np.array(data)
x = x.reshape(2, -1).T
y = np.corrcoef(x[:, 0], x[:, 1])
print(y)数据为:
12.5
15.3
23.2
26.4
33.5
34.4
39.4
45.2
55.4
60.9
21.2
23.9
32.9
34.1
42.5
43.2
49.0
52.8
59.4
63.5
从文件读数据
将list转化为ndarray
计算相关系数
import numpy as np
path = '/home/fhqplzj/IdeaProjects/DocumentClustering/FirstPython/bishe/data.txt'
file = open(path)
def fun(s):
return float(s.strip())
data = list(map(fun, file.readlines()))
x = np.array(data)
x = x.reshape(2, -1).T
y = np.corrcoef(x[:, 0], x[:, 1])
print(y)数据为:
12.5
15.3
23.2
26.4
33.5
34.4
39.4
45.2
55.4
60.9
21.2
23.9
32.9
34.1
42.5
43.2
49.0
52.8
59.4
63.5
相关文章推荐
- python学习----pearsonr(x,y)相关系数计算
- 优矿-python计算上证50之间的相关系数
- Python+pandas计算数据相关系数
- Python+pandas计算数据相关系数的实例
- python - 描述统计学、推断统计学、假设检验、计算person相关系数
- python计算相关系数
- 利用python库计算person相关系数
- 数据挖掘--相关系数计算
- Spearman Rank相关系数计算
- matlab中样本相关系数的计算与测试
- matlab 相关系数的计算
- 【matlab】matlab相关系数计算公式(Pearson和Spearman,以及Kendall Rank)
- python3-经纬度的相关计算
- 期望、方差、协方差及相关系数的原理理解和计算
- 计算 变异系数 标准差 标准偏差 相关系数 平滑指数 回归系数等C++ 模板类
- 回归中的相关系数以及R平方值和Python应用举例
- 【原创】开源Math.NET基础数学类库使用(11)C#计算相关系数
- 相关系数计算
- 开源Math.NET基础数学类库使用(11)C#计算相关系数
- 小白—Python3.5科学计算相关包的安装(Windows系统)