Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用python计算多项式回归系数的标准误差?_Python_Python 3.x_Statistics_Data Science - Fatal编程技术网

如何使用python计算多项式回归系数的标准误差?

如何使用python计算多项式回归系数的标准误差?,python,python-3.x,statistics,data-science,Python,Python 3.x,Statistics,Data Science,一般来说,对于一般线性模型,我使用R,但现在我需要使用python(这是我第一次)。我尝试了两种代码,第一种是绘制数据的回归曲线 import operator from sklearn.pipeline import make_pipeline from sklearn.linear_model import LinearRegression from sklearn.metrics import mean_squared_error, r2_score from sklearn.prepr

一般来说,对于一般线性模型,我使用R,但现在我需要使用python(这是我第一次)。我尝试了两种代码,第一种是绘制数据的回归曲线

import operator

from sklearn.pipeline import make_pipeline
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error, r2_score
from sklearn.preprocessing import PolynomialFeatures

x1=np.log10(s1[0:len(s1)]/mS1)
y1=np.log10(s1[0:len(s1)]**2*Ns1)
x1,y1 = data_cleaner(x1,y1)

# transforming the data to include another axis
x1 = x1[:, np.newaxis]
y1 = y1[:, np.newaxis]

polynomial_features= PolynomialFeatures(degree=3)
x1_poly = polynomial_features.fit_transform(x1)

model = LinearRegression()
model.fit(x1_poly, y1)
y1_poly_pred = model.predict(x1_poly)

rmse = np.sqrt(mean_squared_error(y1,y1_poly_pred))
r2 = r2_score(y1,y1_poly_pred)
print(rmse)
print(r2)

plt.scatter(x1, y1, s=10)
# sort the values of x before line plot
sort_axis = operator.itemgetter(0)
sorted_zip = sorted(zip(x1,y1_poly_pred), key=sort_axis)
x, y_poly_pred = zip(*sorted_zip)
plt.plot(x1, y1_poly_pred, color='m')
plt.xlabel(r'$\log_{10} (s/S(t))$')
plt.ylabel(r'$\log_{10} [s^{2}N_{s}(t)]$')
plt.savefig("polynomial_5min.png")
plt.show()
第二个只计算多项式回归的系数

x1=np.log10(s1[0:len(s1)]/mS1)
y1=np.log10(s1[0:len(s1)]**2*Ns1)
x1,y1 = data_cleaner(x1,y1)

np.polyfit(x1, y1, 3, rcond=False, full=False, w=None, cov=False)
但我还想找出每个系数的标准误差。你知道我怎么做吗


谢谢大家!!这回答了你的问题吗?