下面是我试图实现的代码。我试图生成一个多项式方程来预测y
数组中的下一个值
import numpy as np
import pandas as pd
# creating a dataset with curvilinear relationship
startDay = 32
y = np.array([-60,-63,-65,-64,-64,-71,-70,-74,-74,-73,-73,-70,-71,-74,-74,-75,-75,-74,-72,-73,-76,-76,-76,-76,-74,-73,-76,-76,-77,-77,-75,-75,-73,-73,-77,-77,-77,-76,-74,-73,-74,-76,-75,-77,-76,-73,-70,-73,-75,-75,-75,-76,-74,-70,-72,-74,-74,-74,-73,-70,-68,-69,-72,-72,-72,-72,-70,-67,-69,-68,-69,-70,-70,-65,-64,-63,-67,-67,-66,-68,-63,-60,-63,-64,-65,-66,-64,-60,-58,-61,-62,-64,-63,-61,-57,-56,-56,-59,-60])
endDay = startDay + len(y)
x= np.arange(len(y))
from sklearn.preprocessing import PolynomialFeatures
# for creating pipeline
from sklearn.pipeline import Pipeline
# creating pipeline and fitting it on data
Input=[('polynomial',PolynomialFeatures(degree=2))]
pipe=Pipeline(Input)
pipe.fit(x.reshape(-1,1),y.reshape(-1,1))
poly_pred=pipe.predict(x.reshape(-1,1))
我得到这个错误:
AttributeError: 'PolynomialFeatures' object has no attribute 'predict' on line 9
poly_pred=pipe.predict(x.reshape(-1,1))
我试着在谷歌上搜索,但没有效果。你能告诉我发生了什么,为什么会出错吗
请参阅documentation
PolynomialFeatures
没有任何类似于predict
的方法。本模块不做任何预测,只做数据预处理相关问题 更多 >
编程相关推荐