Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Crossvalidation when dataframe is not provided #801

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion neuralforecast/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ def __init__(
self.models = [deepcopy(model) for model in self.models_init]
self.freq = pd.tseries.frequencies.to_offset(freq)
self.local_scaler_type = local_scaler_type
self.dataset_df = None

# Flags and attributes
self._fitted = False
Expand Down Expand Up @@ -239,6 +240,7 @@ def fit(
if (df is None) and not (hasattr(self, "dataset")):
raise Exception("You must pass a DataFrame or have one stored.")

self.dataset_df = df
# Model and datasets interactions protections
if (any(model.early_stop_patience_steps > 0 for model in self.models)) and (
val_size == 0
Expand Down Expand Up @@ -539,7 +541,7 @@ def cross_validation(
fcsts_df = pd.concat([fcsts_df, fcsts], axis=1)

# Add original input df's y to forecasts DataFrame
fcsts_df = fcsts_df.merge(df, how="left", on=["unique_id", "ds"])
fcsts_df = fcsts_df.merge(df, how="left", on=["unique_id", "ds"]) if df is not None else fcsts_df.merge(self.dataset_df, how="left", on=["unique_id", "ds"])
return fcsts_df

def predict_insample(self, step_size: int = 1):
Expand Down