question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Index out of range.

See original GitHub issue

I am trying to implement this for my predictive neural network but it returns the following error:

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-21-66686af6d687> in <module>()
      5                                           max_evals=5,
      6                                           notebook_name='gridsearch',
----> 7                                           trials=Trials())
      8     x_train, y_train, x_val, y_val = data()
      9     print("Evalutation of best performing model:")

~/anaconda3/envs/poc/lib/python3.6/site-packages/hyperas/optim.py in minimize(model, data, algo, max_evals, trials, functions, rseed, notebook_name, verbose, eval_space, return_space)
     65                                      full_model_string=None,
     66                                      notebook_name=notebook_name,
---> 67                                      verbose=verbose)
     68 
     69     best_model = None

~/anaconda3/envs/poc/lib/python3.6/site-packages/hyperas/optim.py in base_minimizer(model, data, functions, algo, max_evals, trials, rseed, full_model_string, notebook_name, verbose, stack)
     94         model_str = full_model_string
     95     else:
---> 96         model_str = get_hyperopt_model_string(model, data, functions, notebook_name, verbose, stack)
     97     temp_file = './temp_model.py'
     98     write_temp_files(model_str, temp_file)

~/anaconda3/envs/poc/lib/python3.6/site-packages/hyperas/optim.py in get_hyperopt_model_string(model, data, functions, notebook_name, verbose, stack)
    182     imports = extract_imports(cleaned_source, verbose)
    183 
--> 184     parts = hyperparameter_names(model_string)
    185     aug_parts = augmented_names(parts)
    186 

~/anaconda3/envs/poc/lib/python3.6/site-packages/hyperas/optim.py in hyperparameter_names(model_string)
    249             parts.append(name[0])
    250         else:
--> 251             parts.append(parts[-1])
    252     part_dict = {}
    253     for i, part in enumerate(parts):

IndexError: list index out of range

The code used can be found: <script src="https://gist.github.com/GijsVermarien/105a15bc47ff970af5679f4e73d030ee.js"></script>

Id be glad to provide more information if needed.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
GijsVermariencommented, Jun 13, 2018

I have eliminated all the parameters and dumbed it down to just varying the layer size, depth, learning rate and early stopping. Yet it still doesn’t seem to work. See the code attached in this gist: https://gist.github.com/GijsVermarien/c544ab23b9aaffad13c7f4283cff3e8d The error given is still:

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-5-66686af6d687> in <module>()
      5                                           max_evals=5,
      6                                           notebook_name='gridsearch',
----> 7                                           trials=Trials())
      8     x_train, y_train, x_val, y_val = data()
      9     print("Evalutation of best performing model:")

~/anaconda3/envs/poc/lib/python3.6/site-packages/hyperas/optim.py in minimize(model, data, algo, max_evals, trials, functions, rseed, notebook_name, verbose, eval_space, return_space)
     65                                      full_model_string=None,
     66                                      notebook_name=notebook_name,
---> 67                                      verbose=verbose)
     68 
     69     best_model = None

~/anaconda3/envs/poc/lib/python3.6/site-packages/hyperas/optim.py in base_minimizer(model, data, functions, algo, max_evals, trials, rseed, full_model_string, notebook_name, verbose, stack)
     94         model_str = full_model_string
     95     else:
---> 96         model_str = get_hyperopt_model_string(model, data, functions, notebook_name, verbose, stack)
     97     temp_file = './temp_model.py'
     98     write_temp_files(model_str, temp_file)

~/anaconda3/envs/poc/lib/python3.6/site-packages/hyperas/optim.py in get_hyperopt_model_string(model, data, functions, notebook_name, verbose, stack)
    182     imports = extract_imports(cleaned_source, verbose)
    183 
--> 184     parts = hyperparameter_names(model_string)
    185     aug_parts = augmented_names(parts)
    186 

~/anaconda3/envs/poc/lib/python3.6/site-packages/hyperas/optim.py in hyperparameter_names(model_string)
    249             parts.append(name[0])
    250         else:
--> 251             parts.append(parts[-1])
    252     part_dict = {}
    253     for i, part in enumerate(parts):

IndexError: list index out of range
2reactions
JonnoFTWcommented, Sep 13, 2019

My fix for this error was to simply move my parameters into an assigned variable. So replace code like this:

args = {
    'x': {{uniform(0,1)}}
}

With this:

x = {{uniform(0,1)}}
args = {
    'x': x
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

List Index Out of Range – Python Error Message Solved
You'll get the Indexerror: list index out of range error when iterating through a list and trying to access an item that doesn't...
Read more >
Python IndexError: List Index Out of Range Error Explained
We can break down the text a little bit. We can see here that the message tells us that the index is out...
Read more >
Python IndexError: List Index Out of Range [Easy Fix]
The error “list index out of range” arises if you access invalid indices in your Python list. For example, if you try to...
Read more >
What is an "index out of range" exception, and how do I fix it?
Why does this error occur? ... Because you tried to access an element in a collection, using a numeric index that exceeds the...
Read more >
What does the error 'list index out of range' mean?
Generally, list index out of range means means that you are providing an index for which a list element does not exist. Now,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found