# Submission Error MagNet

**URL:** <https://community.drivendata.org/t/submission-error-magnet/5639>\
**Category:** MagNet: Model the Geomagnetic Field\
**Created:** [December 21, 2020, 3:49am UTC](https://community.drivendata.org/t/submission-error-magnet/5639 "2020-12-21T03:49:02Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ammarali32](https://avatars.discourse-cdn.com/v4/letter/a/8baadc/32.png) [@Ammarali32](https://community.drivendata.org/u/Ammarali32)\
**Post date:** [December 21, 2020, 3:49am UTC](https://community.drivendata.org/t/submission-error-magnet/5639/1 "2020-12-21T03:49:02Z")

</div>

I am getting this error and unable to resolve it. any ideas  
File “/codeexecution/predict.py”, line 54, in aggregate\_hourly  
[“period”, feature\_df.index.get\_level\_values(1).floor(“H”)]  
IndexError: Too many levels: Index has only 1 level, not 2  
I am using the Baseline architecture to inference, my model. I appreciate any help and thanks in advance.

---

<div class="post-metadata">

**Author:** ![suyashk12](https://avatars.discourse-cdn.com/v4/letter/s/3d9bf3/32.png) [@suyashk12](https://community.drivendata.org/u/suyashk12)\
**Post date:** [December 21, 2020, 4:43am UTC](https://community.drivendata.org/t/submission-error-magnet/5639/2 "2020-12-21T04:43:43Z")

</div>

You may want to use get\_level\_values(0) - solved the problem for me!

---

<div class="post-metadata">

**Author:** ![iorana](https://avatars.discourse-cdn.com/v4/letter/i/edb3f5/32.png) [@iorana](https://community.drivendata.org/u/iorana)\
**Post date:** [December 21, 2020, 2:36pm UTC](https://community.drivendata.org/t/submission-error-magnet/5639/3 "2020-12-21T14:36:15Z")

</div>

As for me, I had to get rid of `period` in the group by as well.

Do you think it means that the test data does not contain `period` like `train_a`, `train_b` or `train_c`?

---

<div class="post-metadata">

**Author:** ![isms](https://yyz2.discourse-cdn.com/flex028/user_avatar/community.drivendata.org/isms/32/9_2.png) [@isms](https://community.drivendata.org/u/isms)\
**Post date:** [December 21, 2020, 8:41pm UTC](https://community.drivendata.org/t/submission-error-magnet/5639/4 "2020-12-21T20:41:00Z")

</div>

You should not assume the names in the `period` column, treat this as an arbitrary categorical value. @suyashk12’s solution above is the right way to get these out of the DataFrame’s index if you need the specific values.

---

<div class="post-metadata">

**Author:** ![Timothee](https://avatars.discourse-cdn.com/v4/letter/t/48db29/32.png) [@Timothee](https://community.drivendata.org/u/Timothee)\
**Post date:** [January 13, 2021, 2:21pm UTC](https://community.drivendata.org/t/submission-error-magnet/5639/5 "2021-01-13T14:21:29Z")

</div>

Rk: they also forgot to put the numpy library in. Maybe they could correct the benchmark blog post in order to have a working model because as is I had to correct 3 typos to make their benchmark work which makes it loose its interest as an exemplary code.

---

<div class="post-metadata">

**Author:** ![isms](https://yyz2.discourse-cdn.com/flex028/user_avatar/community.drivendata.org/isms/32/9_2.png) [@isms](https://community.drivendata.org/u/isms)\
**Post date:** [January 13, 2021, 8:26pm UTC](https://community.drivendata.org/t/submission-error-magnet/5639/6 "2021-01-13T20:26:18Z")

</div>

> [@Timothee](#):
>
> Rk: they also forgot to put the numpy library in.

What do you mean by this? It looks like numpy is imported in the first code cell.

Please post any typos here, we’d be happy to fix them.

---

<div class="post-metadata">

**Author:** ![Timothee](https://avatars.discourse-cdn.com/v4/letter/t/48db29/32.png) [@Timothee](https://community.drivendata.org/u/Timothee)\
**Post date:** [January 13, 2021, 9:13pm UTC](https://community.drivendata.org/t/submission-error-magnet/5639/7 "2021-01-13T21:13:27Z")

</div>

I mean that from what I understood, we are meant to copy the last cell (cell 31) in a predict.py file that we include in the zip. I beleive that we don’t want to copy the other cells in predict.py.

In this last cell, I had to change three things

- change get\_level\_values(1) to get\_level\_values(0)
- remove the `period` group in the same line as the one where get\_level\_values is
- Add `import numpy as np`

Then with these three corrections, the last cell is indeed good for a prediction.py code for submission. Apart from that the benchmark blog post is very nice so if you can fix (or explain why there are these) typos this would be great.

---

<div class="post-metadata">

**Author:** ![isms](https://yyz2.discourse-cdn.com/flex028/user_avatar/community.drivendata.org/isms/32/9_2.png) [@isms](https://community.drivendata.org/u/isms)\
**Post date:** [January 13, 2021, 10:58pm UTC](https://community.drivendata.org/t/submission-error-magnet/5639/8 "2021-01-13T22:58:51Z")

</div>

Are you sure you are running all the code cells in exactly the same order? As I mentioned `import numpy as np` is at the very top of the benchmark:  
 ![image](https://canada1.discourse-cdn.com/flex028/uploads/drivendata1/original/2X/b/b59c44f2376a99e6894d0c77e9b4fd7740e70f49.png)

---

<div class="post-metadata">

**Author:** ![Timothee](https://avatars.discourse-cdn.com/v4/letter/t/48db29/32.png) [@Timothee](https://community.drivendata.org/u/Timothee)\
**Post date:** [January 14, 2021, 7:40am UTC](https://community.drivendata.org/t/submission-error-magnet/5639/9 "2021-01-14T07:40:35Z")

</div>

And as I mentioned I know that numpy is imported in the first cell but I think the last cell is special, this cell should be copied as is in a `predict.py` file and hence it should come with its own imports. If not why would you re-import panda and keras in the last cell ?

---

<div class="post-metadata">

**Author:** ![cszc](https://avatars.discourse-cdn.com/v4/letter/c/c68b51/32.png) [@cszc](https://community.drivendata.org/u/cszc)\
**Post date:** [January 14, 2021, 4:12pm UTC](https://community.drivendata.org/t/submission-error-magnet/5639/10 "2021-01-14T16:12:19Z")

</div>

@Timothee thanks for flagging these issues! You’re right, `numpy` should be imported in `predict.py`.

I’ve also updated the aggregation line to:

```auto
agged = feature_df.groupby(
            [feature_df.index.floor("H")]
        ).agg(aggs)

```

You should see these changes today. Thanks again for flagging!
