RuntimeError:隐藏0_WN中的NaN,找不到记录器“sknn”scikit-neuralnetwork的处理程序

时间:2015-11-02 13:42:13

标签: python scikit-learn neural-network theano scikits

我正在尝试在Python中实现神经网络分类器。这是函数的片段

def create_and_train_nn(train_predictors,train_responses):

   print '\t\tcreating Neural Network'
   nn = Classifier(
   layers=[
       Layer("Maxout", units=100, pieces=2),
       Layer("Softmax")],
   learning_rate=0.001,
   n_iter=25)
   print '\t\tNeural Network created successfully'

   print '\t\ttraining Neural Network'
   fit = nn.fit(train_predictors,train_responses)
   print "NN Fitted"

   print '\t\tNeural Network successfully trained'

   return nn

执行代码后,我收到以下错误。

No handlers could be found for logger "sknn"
   Traceback (most recent call last):
     File "D:/Predictive-Analytics/CodeBase/Tests/balanceClasses/parameterTesting/neural_1.py", line 590, in <module>
       start(table1='small_ds1_tse_temporal_lookback6',table2='balanced_new_small_ds1_tse_temporal_lookback6_m1_6hr_0106')
     File "D:/Predictive-Analytics/CodeBase/Tests/balanceClasses/parameterTesting/neural_1.py", line 588, in start
       main(table1,table2,30,5,'gini',100,fname,start_date,end_date,i+1,ds)
     File "D:/Predictive-Analytics/CodeBase/Tests/balanceClasses/parameterTesting/neural_1.py", line 257, in main
       nn = create_and_train_nn(train_predictors,train_responses)
     File "D:/Predictive-Analytics/CodeBase/Tests/balanceClasses/parameterTesting/neural_1.py", line 481, in create_and_train_nn
       fit = nn.fit(train_predictors,train_responses)
     File "C:\Users\Dickson\Anaconda\lib\site-packages\sknn\mlp.py", line 283, in fit
       return super(Classifier, self)._fit(X, yp)
     File "C:\Users\Dickson\Anaconda\lib\site-packages\sknn\mlp.py", line 157, in _fit
       raise e
   RuntimeError: NaN in hidden0_W

我已经搜索了错误,并提出了一些将学习率降低10倍的建议。但即便如此,问题依然存在。加上没有其他解决方案似乎运作良好。我都无法理解这个错误与上下文有什么关系。任何帮助都会有所帮助。

1 个答案:

答案 0 :(得分:0)

我还得到了“没有找到处理程序......训练分歧并返回NaN”错误的fit()命令。你需要做两件事。

首先,将以下内容添加到代码顶部:

import logging
logging.basicConfig()

其次,您需要规范化数据,使输入为[-1,1]或[0,1]。

我正在训练我的神经网络对图像进行分类,一旦我使用以下方法对图像值进行归一化:

#normalize data
img *= (1.0/img.max())

它有效。祝福,希望这会有所帮助!