【问题标题】:Python; SciKit Learn; SVM; Shape MismatchPython; SciKit 学习;支持向量机;形状不匹配
【发布时间】:2016-01-31 00:01:59
【问题描述】:

我有 40,000 个资产的时间序列。我已将数据拆分为训练数据和目标数据。训练数据有 119 天的回报,目标数据有 59 天。我是故意这样拆分的。

Train:(119 行返回,40000 个不同系列) 目标:(59行返回,同40000系列)

我运行了以下代码来拟合模型:

SVR_model = svm.SVR(kernel='rbf',C=100,gamma=.001).fit(t_train_scale.transpose(), t_test.transpose())
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-185-2a0fd827e2a4> in <module>()
      1 
      2 
----> 3 SVR_model = svm.SVR(kernel='rbf',C=100,gamma=.001).fit(t_train_scale.transpose(), t_test.transpose())

C:\Users\nnayyar\Anaconda\lib\site-packages\sklearn\svm\base.pyc in fit(self, X, y, sample_weight)
    174 
    175         seed = rnd.randint(np.iinfo('i').max)
--> 176         fit(X, y, sample_weight, solver_type, kernel, random_seed=seed)
    177         # see comment on the other call to np.iinfo in this file
    178 

C:\Users\nnayyar\Anaconda\lib\site-packages\sklearn\svm\base.pyc in _dense_fit(self, X, y, sample_weight, solver_type, kernel, random_seed)
    229                 cache_size=self.cache_size, coef0=self.coef0,
    230                 gamma=self._gamma, epsilon=self.epsilon,
--> 231                 max_iter=self.max_iter, random_seed=random_seed)
    232 
    233         self._warn_from_fit_status()

C:\Users\nnayyar\Anaconda\lib\site-packages\sklearn\svm\libsvm.pyd in sklearn.svm.libsvm.fit (sklearn\svm\libsvm.c:1864)()

ValueError: Buffer has wrong number of dimensions (expected 1, got 2)

从研究中,我看到使用 SVM 最常见的答案是形状必须“匹配”,但如何使 SVM 适合各种大小的数据?

编辑:仍然需要一些帮助,我如何预测数千个预测,而不仅仅是下一个?

【问题讨论】:

  • 训练有 119 天的回报,目标有 59 天的回报是什么意思?
  • 我在训练集中有119天的回报信息,在目标集中有59天的回报。所以库存 1 的 40,000;第 1 天返回 X,第 2 天返回 Y....有意义吗?

标签: python scikit-learn svm


【解决方案1】:

问题在于fit 调用中的第二个参数。

作为per documentation,第二个参数需要是一个包含 n 个样本的数组,其中 n 是实例数,等于您作为第一个参数 (X) 传递的矩阵的行数。

fit(X, y, sample_weight=None)

X : {array-like, sparse matrix}, shape (n_samples, n_features)

y : 类数组,形状 (n_samples,)

因此,如果您的第一个参数的大小为 40.000 x 119(因为您已转置它),则第二个参数需要是大小为 40.000 x 1 的数组。

但是,根据错误判断,您的第二个参数可能超过 1 列(即 2 列)。

【讨论】:

  • 谢谢,第二个数组是 40,000 x 59!所以也许这会有所帮助,我有 1 年的数据,我想使用前六个月的 DAILY 数据来预测接下来六个月的 DAILY 回报。我需要一次预测收益 1 吗?
猜你喜欢
  • 2015-06-03
  • 2017-05-17
  • 2013-06-14
  • 1970-01-01
  • 2022-12-06
  • 2016-10-09
  • 2017-08-18
  • 1970-01-01
相关资源
最近更新 更多