数组尺寸值错误



我计算了一个数组,它的形状为800*1140。narray是从上一步生成的,元素使用hstack进行堆叠。我需要将其插入scikitlearn进行培训,并且我有以下错误:

ValueError: Found array with dim 1140。预期800

我想我的错误可能与此相似,但我不知道如何进行。

谁能给我指点一下吗?下面是导致错误的代码:在运行XTrain..... 时导致错误
X_scaled = preprocessing.scale(self.featureMatrix)
imp = Imputer(missing_values='NaN', strategy='mean', axis=0)
X_scaled = imp.fit_transform(X_scaled)
classiFier = svm.SVC(C=10, cache_size=1500, class_weight=None, coef0=0.0, degree=3, gamma=0.0, kernel='rbf', max_iter=-1, probability=False, random_state=None, shrinking=True, tol=0.001, verbose=False)
XTrain, XTest, yTrain, yTest = cv.train_test_split(X_scaled,
                                                       self.classID,
                                                       test_size=0.4,
                                                       random_state=0)

这是整个Traceback:

Traceback (most recent call last):
File "C:Program Files (x86)JetBrainsPyCharm Community Edition 
4.5.3helperspydevpydevd.py", line 2358, in <module>
globals = debugger.run(setup['file'], None, None, is_module)
File "C:Program Files (x86)JetBrainsPyCharm Community Edition
4.5.3helperspydevpydevd.py", line 1778, in run
pydev_imports.execfile(file, globals, locals)  # execute the script
File "C:Program Files (x86)JetBrainsPyCharm Community Edition#
4.5.3helperspydev_pydev_imps_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"n", file, 'exec'), glob, loc) 
File "C:/Users/vaidvj/svn/idmt/core/wrappers/afp/test/data/Urban_Sound_DB
/train&testSVM_MF.py", line 133, in <module>
c.process()
File "C:/Users/vaidvj/svn/idmt/core/wrappers/afp/test/data/Urban_Sound_DB
/train&testSVM_MF.py", line 129, in process
self.confMatcal( self.MfeatureMatrix, self.classID, self.uniqueClassLabels)
File "C:/Users/vaidvj/svn/idmt/core/wrappers/afp/test/data/Urban_Sound_DB/train&testSVM_MF.py", line 49, in confMatcal
random_state=0)
File "C:Anaconda3libsite-packagessklearncross_validation.py", line 1556, in train_test_split
arrays = check_arrays(*arrays, **options)
File "C:Anaconda3libsite-packagessklearnutilsvalidation.py", line 254, in check_arrays
% (size, n_samples))
ValueError: Found array with dim 1140. Expected 800

谢谢。

您应该使用numpy.transpose()yourArray.T来转换您的数据。scikit期望一个形状为(n_samples, n_features)的数组,其中n_samples是您的观察数,n_features是它们所在空间的维度。

参见np.transpose()文档中的示例

相关内容

  • 没有找到相关文章

最新更新