Open vishnu020 opened 9 months ago
I'm assuming filtered_base_data
does not have the "total_sales" column. Since you are using the same parameters as training
(in which target
is set to "total_sales") to create inference_ts_dataset
, it complains because it can't find "total_sales" in filtered_base_data
.
I don't think this necessarily means there is data leakage in predict
.
@vishnu020 if that solved your problem, consider closing the issue.
!pip install lightning !pip install pytorch-forecasting !pip install torch !pip install optuna==3.4 !pip install torch==2.0.1
This code is working fine but when i tried to forecast on unseen data below it is giving error
##It is giving the following error
KeyError Traceback (most recent call last) ~\AppData\Roaming\Python\Python39\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance) 3801 try: -> 3802 return self._engine.get_loc(casted_key) 3803 except KeyError as err:
~\AppData\Roaming\Python\Python39\site-packages\pandas_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()
~\AppData\Roaming\Python\Python39\site-packages\pandas_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
pandas_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 'total_sales'
The above exception was the direct cause of the following exception:
KeyError Traceback (most recent call last) ~\AppData\Local\Temp\ipykernel_27744\1361187920.py in
----> 1 inference_ts_dataset = TimeSeriesDataSet.from_parameters(data= filtered_base_data, parameters=params, predict=True)
2 predictions = model.predict(inference_ts_dataset.to_dataloader(train=False), raw=True)
~\AppData\Roaming\Python\Python39\site-packages\pytorch_forecasting\data\timeseries.py in from_parameters(cls, parameters, data, stop_randomization, predict, update_kwargs) 1198 parameters.update(update_kwargs) 1199 -> 1200 new = cls(data, parameters) 1201 return new 1202
~\AppData\Roaming\Python\Python39\site-packages\pytorch_forecasting\data\timeseries.py in init(self, data, time_idx, target, group_ids, weight, max_encoder_length, min_encoder_length, min_prediction_idx, min_prediction_length, max_prediction_length, static_categoricals, static_reals, time_varying_known_categoricals, time_varying_known_reals, time_varying_unknown_categoricals, time_varying_unknown_reals, variable_groups, constant_fill_strategy, allow_missing_timesteps, lags, add_relative_time_idx, add_target_scales, add_encoder_length, target_normalizer, categorical_encoders, scalers, randomize_length, predict_mode) 474 475 # preprocess data --> 476 data = self._preprocess_data(data) 477 for target in self.target_names: 478 assert target not in self.scalers, "Target normalizer is separate and not in scalers."
~\AppData\Roaming\Python\Python39\site-packages\pytorch_forecasting\data\timeseries.py in _preprocess_data(self, data) 742 f"target{target}" not in data.columns 743 ), f"target{target} is a protected column and must not be present in data" --> 744 data[f"target{target}"] = data[target] 745 if self.weight is not None: 746 data["weight"] = data[self.weight]
~\AppData\Roaming\Python\Python39\site-packages\pandas\core\frame.py in getitem(self, key) 3805 if self.columns.nlevels > 1: 3806 return self._getitem_multilevel(key) -> 3807 indexer = self.columns.get_loc(key) 3808 if is_integer(indexer): 3809 indexer = [indexer]
~\AppData\Roaming\Python\Python39\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance) 3802 return self._engine.get_loc(casted_key) 3803 except KeyError as err: -> 3804 raise KeyError(key) from err 3805 except TypeError: 3806 # If we have a listlike key, _check_indexing_error will raise
KeyError: 'total_sales'