stock_prediction test.py ValueError: Length of values (445) does not match length of index (447)
hol-42 opened this issue · 5 comments
Get the following error. Cannot figure out how to correct it.
Traceback (most recent call last):
File "test.py", line 103, in <module>
final_df = get_final_df(model, data)
File "test.py", line 43, in get_final_df
test_df[f"adjclose_{LOOKUP_STEP}"] = y_pred
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/core/frame.py", line 3044, in __setitem__
self._set_item(key, value)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/core/frame.py", line 3120, in _set_item
value = self._sanitize_column(key, value)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/core/frame.py", line 3768, in _sanitize_column
value = sanitize_index(value, self.index)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/core/internals/construction.py", line 747, in sanitize_index
raise ValueError(
ValueError: Length of values (445) does not match length of index (447)
Hi @hol-42 ,
I cannot reproduce the error, can you share the parameters you used in parameters.py ?
Thanks,
Thanks for your reply. The parameter I changed was ticker:
ticker = "BTC-USD"
It worked well for AMZN but not for BTC-USD
Hi @hol-42 ,
Thanks for pointing out, it turns out that some tickers have duplicated dates (so testing has 447 samples and prediction has 445 -true value). As a result, I've added a line in the end of load_data() function to remove duplicated dates.
It should work now, check the code again. Thanks for pointing out!
Please let me know if this solved the problem.
Thanks,
Thank you very much. Yes this worked.
I thought it was something like that but my Python skills still develop.
Great project, by the way.
Do well and happy 2021.
- hol42
Thank you very much!