我正在使用scipy绘制数据矩阵X中一组特征变量的正常可行性图。但是,我正在使用的模块没有返回我的r ^ 2值。这是我的简单代码:
Data_Matrix=pd.read_csv('My csv')
My_datum=My_Data.as_matrix()
#loop through all feature variables
for i in range(My_datum.shape[1]):
#just a simple print line for the column index and its shapiro test
results
print(i)
print(a)
#plot
pplot=stats.probplot(My_datum[:,i],dist='norm',fit=True, plot=plt )
a=sp.stats.shapiro(My_datum[:,i])
我尝试在一些更简单的numpy数组上使用相同的行,但无济于事。我在spyder 3上使用Ipython控制台。提前感谢!
答案 0 :(得分:2)
Probplot已经返回R值。你只需要将它平方给你R ^ 2.
c
答案 1 :(得分:1)
所以这有点奇怪,但它返回一个元组列表。您实际上只需要通过索引 probplot 函数从列表中提取第二个元组。您需要解压元组,然后将其平方。
slope, intercept, r = stats.probplot(My_datum[:,i], dist='norm', fit=True, plot=plt)[1]
r2 = r**2