2015-10-30 111 views
1

我有40,000个资产的时间序列。我已将数据分为训练数据和目标数据。培训数据有119天的回报,目标数据有59天。我故意将它分解成这种方式。Python; SciKit学习; SVM;形状不匹配

火车:(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适合各种大小的数据?

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

+0

你的培训意味着什么119天的回报和目标有59天的回报? – WoodChopper

+0

我在训练集中有119天的回报信息,在目标集中有59天的回报。所以库存1万4千;第1天返回X,第2天返回Y ....有道理? – user2977664

回答

0

问题出在您拨打fit时的第二个参数。

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

拟合(X,Y,sample_weight =无)

X:{阵列状,稀疏矩阵},形状(N_SAMPLES次,n_features)

Y: 阵列状,形状( N_SAMPLES次)

所以,如果你的第一个参数的大小为40.000 x 119(因为你调换的话),第二个参数必须是大小40.000 x 1的数组。

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

+0

谢谢,第二个数组是40,000 x 59!所以也许这会有所帮助,我有1年的数据,我想用前六个月的每日数据来预测未来六个月的每日回报。我需要一次预测回报1吗? – user2977664