1

I am trying to implement the Neural Network Classifier in Python. Here is the snippet of the function

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

And after executing the code, I got the following error.

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

I have googled the error and there some suggestions to lower the learning rate by 10x. But even after that the problem persists. Plus no other solution seems o be working well. Neither I'm able to understand in what context is this error related to. Any help would really be helpful.

Debasish Kanhar
  • 1,123
  • 2
  • 15
  • 27

1 Answers1

0

I also got the "No handlers found .... Training diverged and returned NaN" erroring out on the fit() command. You need to do two things.

First, add the following to the top of your code:

import logging
logging.basicConfig()

Second, you need to normalize your data so that the input is [-1,1] or [0,1].

I was training my neural network to classify images and once I normalize the image values using:

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

and it worked. Best wishes, hope this helps!

za_roxy
  • 111
  • 1
  • 5