开发者

Is it possible to create a sklearn multivariate polynomial regression that is cubic in one term and linear in the other?

I am trying to model a relationship in python using multiple terms including a time term but the model I am trying to recreate is one that uses a cubic polynomial in one variable and a linear polynomial in the time term. In other words, the model is in the following form:

y = c1 + c2*x + c3*x**2 + c4*x**3 + c5*time + error

I have already used sklearn to create a polynomial regression to model the relationship between x and y but I am struggling to understand how to to extend this model to include a linear time term.

I have tried to approach the problem using the built in multivariate regression features but these seem to always put the relationship between all involved terms as a cubic relationship. The (very primitive) code I utilized for this was the following:

xtime = = np.stack([x,time],axis=1)
polyfeatures = PolynomialFeatures(degree=3)
feat = polyfeatures.fit_transform(xtime)
for i in range(len(feat)):
    feat[i][4] = 0
    feat[i][5] = 0
    feat[i][7] = 0
    feat[i][8] = 0
    feat[i][9] = 0

The thinking behind this was to zero out all of the exponent values in feat that corresponded to terms that were not in the final equation that I was looking to create. The result of this attempt was (unsurprisingly) a very poor regression that did not correlate with the 开发者_开发问答data whatsoever.

If anyone has any recommendations I would be extremely grateful. Thank you so much for any help!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜