我正在尝试使用nolearn训练一个dbm,但由于某种原因它失败了。每个训练样本都是1.0的向量,Test也是如此。当我使用“真实”输入时,我得到了同样的错误。
训练代码与nolearn文档中关于MNIST的训练代码几乎相同。
# import the necessary packages
from sklearn.cross_validation import train_test_split
from sklearn.metrics import classification_report
from sklearn.metrics import confusion_matrix
from sklearn import datasets
from nolearn.dbn import DBN
# scale the data to the range [0, 1] and then construct the training
# and testing splits
(trainX, testX, trainY, testY) = train_test_split( features , targets , test_size = 0.33)
print trainX.shape
print trainY.shape
dbn = DBN(
[trainX.shape[1], 80, 80, trainY.shape[1]],
learn_rates = 0.3,
learn_rate_decays = 0.9,
epochs = 10,
verbose = 1)
dbn.fit(trainX, trainY)
# compute the predictions for the test data and show a classification
# report
preds = dbn.predict(testX)由于一些我找不到的原因,它失败了:
100%
---------------------------------------------------------------------------
ZeroDivisionError Traceback (most recent call last)
<ipython-input-4-5324a7be4932> in <module>()
19 epochs = 10,
20 verbose = 1)
---> 21 dbn.fit(trainX, trainY)
22
23 # compute the predictions for the test data and show a classification
/usr/local/lib/python2.7/dist-packages/nolearn/dbn.pyc in fit(self, X, y)
388 loss_funct,
389 self.verbose,
--> 390 self.use_dropout,
391 )):
392 losses_fine_tune.append(loss)
/usr/local/lib/python2.7/dist-packages/gdbn/dbn.pyc in fineTune(self, minibatchStream, epochs, mbPerEpoch, loss, progressBar, useDropout)
207 prog.tick()
208 prog.done()
--> 209 yield sumErr/float(totalCases), sumLoss/float(totalCases)
210
211 def totalLoss(self, minibatchStream, lossFuncts):
ZeroDivisionError: float division by zero
gnumpy: failed to import cudamat. Using npmat instead. No GPU will be used.
(1, 200)
(1, 125)
[DBN] fitting X.shape=(1, 200)
[DBN] layers [200, 80, 80, 125]
[DBN] Fine-tune...发布于 2015-03-05 22:25:05
验证trainY.shape[1]是否与您的类数相同。
我以前遇到过这个问题,并确保那些匹配的解决了它。
发布于 2015-12-19 14:53:35
为了避免这个错误,我从pandas dataframes切换到numpy数组。
发布于 2016-09-27 14:49:43
我相信你的训练数据集可能很小。只需在您的DBN对象minibatch_size=1中再添加一个参数,默认情况下它是minibatch_size=64。您可以根据自己的需求进一步调整。示例:
dbn = DBN(
[trainX.shape[1], 300, 5],
learn_rates = 0.3,
learn_rate_decays = 0.9,
epochs = 10,
verbose = 1,
minibatch_size=1)https://stackoverflow.com/questions/27590302
复制相似问题