我正在尝试使用时间序列数据上的sklearn拟合线性回归。唯一的问题是,据我所知,数据不符合通常的时间序列格式。
下面是一个示例:
[ [ [ [2312, 31242], [2312, 13212] ], [ [2323, 21312], [12312, 1232] ] ], [ [ [9312, 91242], [2812, 73212] ], [ [2393, 25612], [14162, 132437] ] ], and so on... ]
我很抱歉,如果这有点难读,但我的想法是,每个列表都代表了当时的一些上下文,其中的每个列表(包含两个列表和两个项目的列表)。这是可以的,除非我有多个上下文,但我希望它们都在同一个模型上训练。有什么办法吗?
以下是我尝试过的:
model = sklearn.pipeline.make_pipeline(sklearn.preprocessing.StandardScaler(), sklearn.linear_model.SGDRegressor(max_iter=1000, tol=1e-3)) limiteds_np = np.array([i.numpy() for i in cache.limiteds_cache]) X = some data in the format I described y = for each time series the next series in that series model.fit(X, y)
再次,我很抱歉,这段代码无法运行,但我只需要深入了解这个问题,以便解决它。
顺便说一句,当运行上面的代码(使用我的数据)时,我会得到逻辑上的错误:
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) TypeError: only size-1 arrays can be converted to Python scalars The above exception was the direct cause of the following exception: ValueError Traceback (most recent call last) /Users/sebastianlarson/Dev/arbi-blox/src/test_algorithm.ipynb Cell 10 in <cell line: 15>() 13 X = np.array(X) 14 y = np.array(y) ---> 15 model.fit(X, y) File /usr/local/Caskroom/miniconda/base/lib/python3.9/site-packages/sklearn/pipeline.py:378, in Pipeline.fit(self, X, y, **fit_params) 352 """Fit the model. 353 354 Fit all the transformers one after the other and transform the (...) 375 Pipeline with fitted steps. 376 """ 377 fit_params_steps = self._check_fit_params(**fit_params) --> 378 Xt = self._fit(X, y, **fit_params_steps) 379 with _print_elapsed_time("Pipeline", self._log_message(len(self.steps) - 1)): 380 if self._final_estimator != "passthrough": File /usr/local/Caskroom/miniconda/base/lib/python3.9/site-packages/sklearn/pipeline.py:336, in Pipeline._fit(self, X, y, **fit_params_steps) ... 858 raise ValueError( 859 "Complex data not supported\n{}\n".format(array) 860 ) from complex_warning ValueError: setting an array element with a sequence.
因为(继续我上面所说的),sklearn需要以下格式的数据:
[[12, 23], [324, 2345], [454, 234]]