-1

I have a plot-

enter image description here

When I am trying to do linear regression on it-

df=pd.read_csv('tau.csv')


xx= df['xx'].tolist()
yy=df['yy'].tolist()
from scipy.stats import linregress
#print(linregress(xx,yy))

slope, intercept, r_value, p_value, std_err=linregress(xx,yy)
print(slope)

plt.plot(xx,yy,'ro')
plt.xlabel('log(l)')
plt.ylabel('log(Rl)')
plt.title('Fractal dimension with '+str(slope))
plt.show()

I get the slope as nan.

my data-

enter image description here

ubuntu_noob
  • 2,305
  • 6
  • 23
  • 64
  • Possible duplicate of [Linear regression of arrays containing NANs in Python/Numpy](https://stackoverflow.com/questions/13643363/linear-regression-of-arrays-containing-nans-in-python-numpy) – meyi Jul 12 '19 at 22:52

1 Answers1

1

Looks like you have nan in your data:

x = [1,2, np.nan]
y = [2,4,6]

linregress(x,y)

>>> LinregressResult(slope=nan, intercept=nan, rvalue=nan, pvalue=nan, stderr=nan)

Also, you don't need to convert series to list, you can certainly do:

lingress(df['xx'], df['yy'])
Quang Hoang
  • 146,074
  • 10
  • 56
  • 74
  • This looks like the right explanation, although the docs for scipy 1.3 `linregress` appear to claim that missing data is handled "in pairs". Looking at the source of "linregress", I don't think that it is the case. – hilberts_drinking_problem Jul 12 '19 at 22:56