繁体   English   中英

如何从多项式拟合线性回归 model 中的给定 Y 值预测 X 值?

[英]How can I predict X value from a given Y value from a polynomial fitted Linear Regression model?

在拟合了一个简单的线性回归 model 之后,我使用了这个公式:“y=mx+c”来找到给定“y”值的“x”值。 显然,安装了 model,我得到了“m”和“c”的值。

model = LinearRegression(fit_intercept=True)
model.fit(X,Y)
print('intercept:', model.intercept_)
print('slope:', model.coef_)
intercept: 1.133562363647583
slope: [-0.00075101]
#finding 'x' val for y=1 : x=(y-c)/m
x=(1-model.intercept_)/model.coef_[0] 

现在,我认为 Linear 做得不好,并且看到3 次多项式拟合给出了最好的结果(不包括这里的图表)。 现在,如何从下面的代码片段中预测给定“y”值的“x”值:

from sklearn.preprocessing import PolynomialFeatures
poly = PolynomialFeatures(degree = 3) 
X_poly = poly.fit_transform(X) 
  
poly.fit(X_poly, Y) 
model2 = LinearRegression(fit_intercept=True) 
model2.fit(X_poly, Y)

print('intercept:', model2.intercept_)
print('slope:', model2.coef_)
intercept: 1.461870542630406
slope: [ 0.00000000e+00 -1.12408245e-02  9.69531205e-05 -2.72315461e-07]

尝试

p = [slope, intercept - y]

x = numpy.roots(p)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM