我正在处理这种类型的数据:
Date Of Stop count
0 2012-01-01 180
1 2013-01-01 348
2 2014-02-01 537
3 2015-02-01 498
4 2016-03-01 719
5 2017-03-01 406
并尝试对我没有数据(日期)的日期进行预测
这是我的代码,其中我将日期分为前11个月和第12个月 然后我尝试根据前11个月定义在12个月后可以得到什么
dfhalf = groupbyClass[(groupbyClass['Date Of Stop'] > '01/01/2012') &
(groupbyClass['Date Of Stop'] < '12/01/2012')]
dfpred = groupbyClass[(groupbyClass['Date Of Stop'] >= '12/01/2012') &
(groupbyClass['Date Of Stop'] < '01/01/2013')]
from sklearn.linear_model import LinearRegression
X = dfhalf['Date Of Stop'] # put dates in here
y = dfhalf['count'] # put knowh in here
model = LinearRegression()
model.fit(X, y)
X_predict = dfpred['Date Of Stop'] # dates for prediction
y_predict = model.predict(X_predict)
不幸的是,这会向我抛出这样的东西:
ValueError: Expected 2D array, got 1D array instead:
array=['2012-01-02T00:00:00.000000000' '2012-01-03T00:00:00.000000000'
'2012-01-04T00:00:00.000000000' '2012-01-05T00:00:00.000000000'
'2012-01-06T00:00:00.000000000' '2012-01-07T00:00:00.000000000'
'2012-01-08T00:00:00.000000000' '2012-01-09T00:00:00.000000000'
'2012-01-10T00:00:00.000000000' '2012-01-11T00:00:00.000000000'
....
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.
在定义X或y时,我尝试使用.reshape(-1、1和(1,-1)的不同形式。但是没有运气。我不知道我需要做什么以及为什么。 / p>