Python Nolearn DBM无法训练

Python Nolearn DBM无法训练,python,neural-network,Python,Neural Network,我正在尝试使用nolearn来训练dbm,但出于某种原因,它失败了。 每个列车示例都是1.0的向量,用于测试。当我使用“真实”输入时,我得到了相同的错误 培训代码与nolearn文档中MNIST培训代码几乎相同 # import the necessary packages from sklearn.cross_validation import train_test_split from sklearn.metrics import classification_report from skl

我正在尝试使用nolearn来训练dbm,但出于某种原因,它失败了。 每个列车示例都是1.0的向量,用于测试。当我使用“真实”输入时,我得到了相同的错误

培训代码与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...
100%
---------------------------------------------------------------------------
ZeroDivisionError回溯(最近一次呼叫上次)
在()
19个时代=10,
20详细=1)
--->21直径配合(第X列、第Y列)
22
23#计算测试数据的预测并显示分类
/usr/local/lib/python2.7/dist-packages/nolearn/dbn.pyc-in-fit(self,X,y)
388损失函数,
389自我冗长,
-->390自用退出,
391                 )):
392损失\u微调。追加(损失)
/fineTune中的usr/local/lib/python2.7/dist-packages/gdbn/dbn.pyc(self、minibatchStream、epochs、mbPerEpoch、loss、progressBar、useDropout)
207程序勾选()
208程序完成()
-->209苏美尔产量/浮动(总案例)、苏美尔损失/浮动(总案例)
210
211 def totaloss(self、minibatchStream、lossFunts):
ZeroDivisionError:浮点除以零
gnumpy:导入cudamat失败。使用npmat代替。不使用GPU。
(1, 200)
(1, 125)
[DBN]拟合X.shape=(1200)
[DBN]层[200,80,80,125]
[DBN]微调。。。

验证
trany.shape[1]
是否与您的课程编号相同


我以前有过一次这个问题,并确保匹配者修复了它。

为了避免这个错误,我从pandas数据帧切换到numpy数组。

我相信您的训练数据集可能很小。只需在DBN对象中再添加一个参数,
minibatch\u size=1
,默认情况下它是
minibatch\u size=64
。您可以根据需要进一步调整。 例如:


这并不能真正回答问题。如果您有不同的问题,可以单击以提问。一旦你有足够的时间,你也可以对这个问题给予更多的关注。@Barranka,正如我所说,我也有同样的问题,这至少对我来说是一个解决方案(其中一个参数不正确)。
dbn = DBN(
    [trainX.shape[1], 300, 5],
    learn_rates = 0.3,
    learn_rate_decays = 0.9,
    epochs = 10,
    verbose = 1,
    minibatch_size=1)