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.
You may want to use get_level_values(0) - solved the problem for me!
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
?
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.
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.
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.
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.
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:
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 ?
@Timothee thanks for flagging these issues! You’re right, numpy
should be imported in predict.py
.
I’ve also updated the aggregation line to:
agged = feature_df.groupby(
[feature_df.index.floor("H")]
).agg(aggs)
You should see these changes today. Thanks again for flagging!