【发布时间】:2015-09-09 13:05:48
【问题描述】:
我正在尝试根据一些数据训练系统,Sound_Fc 是一个 16X1 浮点数组。
for i in range(0,26983):
Block_coo = X[0,i]
Fc = Block_coo[4]
Sound_Fc = Fc[:,0]
Vib_Fc = Fc[:,1]
y = np.matrix([[1.0],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12],[13],[14],[15],[16]])
testX, trainY, testY) = train_test_split(
Sound_Fc, y, test_size = 0.33, random_state=42)
dbn = NeuralNet(
layers=[
('input', layers.InputLayer),
('hidden', layers.DenseLayer),
('output', layers.DenseLayer),
],
input_shape = (None, trainX.shape[0]),
hidden_num_units=8,
output_num_units=4,
output_nonlinearity=softmax,
update=nesterov_momentum,
update_learning_rate=0.3,
update_momentum=0.9,
regression=False,
max_epochs=5,
verbose=1,
)
dbn.fit(trainX,trainY)
但是我收到了这个错误
Warning (from warnings module):
File "C:\Users\Essam Seddik\AppData\Roaming\Python\Python27\site-packages\sklearn\cross_validation.py", line 399
% (min_labels, self.n_folds)), Warning)
Warning: The least populated class in y has only 1 members, which is too few. The minimum number of labels for any class cannot be less than n_folds=5.
Traceback (most recent call last):
File "C:\Essam Seddik\Deep Learning Python Tutorial\DNV_DeepLearn.py", line 77, in <module>
dbn.fit(trainX,trainY)
File "C:\Python27\lib\site-packages\nolearn-0.6adev-py2.7.egg\nolearn\lasagne\base.py", line 293, in fit
self.train_loop(X, y)
File "C:\Python27\lib\site-packages\nolearn-0.6adev-py2.7.egg\nolearn\lasagne\base.py", line 300, in train_loop
X, y, self.eval_size)
File "C:\Python27\lib\site-packages\nolearn-0.6adev-py2.7.egg\nolearn\lasagne\base.py", line 401, in train_test_split
kf = StratifiedKFold(y, round(1. / eval_size))
File "C:\Users\Essam Seddik\AppData\Roaming\Python\Python27\site-packages\sklearn\cross_validation.py", line 416, in __init__
label_test_folds = test_folds[y == label]
IndexError: too many indices for array
我尝试用 xrange 代替 range,用 y=list() 代替定义的 y。我还尝试了 for 循环范围内的小数字,例如 5、10 和 100,而不是 26983。 我尝试了 np.array 和 np.ndarray 和 np.atleast_2d。没有任何效果!
【问题讨论】:
标签: python-2.7 numpy scikit-learn