Obtaining Polynomial Regression Stats in Numpy
Do you need the stats? If not, and you just need the coefficients, it's really quite simple using numpy.polyfit
:
import numpy as np
# from your code
data1 = np.loadtxt('/home/script/2_columns', delimiter=',', skiprows=0)
x = data1[:,0]
y = data1[:,1]
degree = 3
coeffs = np.polyfit(x, y, degree)
# now, coeffs is an array which contains the polynomial coefficients
# in ascending order, i.e. x^0, x^1, x^2
intercept, linear, quadratic, cubic = coeffs
If you do need the other values, please specify what you need, since for example the r_value
is the correlation coefficient between x
and y
, which isn't very useful when you don't expect the data to be linear.