sort date index
Browse files
app.py
CHANGED
|
@@ -14,23 +14,41 @@ def offset_calculation(prediction_length, rolling_windows, length):
|
|
| 14 |
return row_offset
|
| 15 |
|
| 16 |
|
| 17 |
-
def preprocess(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
df = pd.read_csv(input_data.name, index_col=0, parse_dates=True)
|
|
|
|
| 19 |
row_offset = offset_calculation(prediction_length, rolling_windows, len(df))
|
| 20 |
return plot_train_test(df.iloc[:row_offset], df.iloc[row_offset:])
|
| 21 |
|
| 22 |
|
| 23 |
-
def train_and_forecast(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
if not input_data:
|
| 25 |
raise gr.Error("Upload a file with the Upload button")
|
| 26 |
try:
|
| 27 |
df = pd.read_csv(input_data.name, index_col=0, parse_dates=True)
|
|
|
|
| 28 |
except AttributeError:
|
| 29 |
raise gr.Error("Upload a file with the Upload button")
|
| 30 |
|
| 31 |
row_offset = offset_calculation(prediction_length, rolling_windows, len(df))
|
| 32 |
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
training_data, test_gen = split(gluon_df, offset=row_offset)
|
| 36 |
|
|
|
|
| 14 |
return row_offset
|
| 15 |
|
| 16 |
|
| 17 |
+
def preprocess(
|
| 18 |
+
input_data,
|
| 19 |
+
prediction_length,
|
| 20 |
+
rolling_windows,
|
| 21 |
+
item_id,
|
| 22 |
+
progress=gr.Progress(track_tqdm=True),
|
| 23 |
+
):
|
| 24 |
df = pd.read_csv(input_data.name, index_col=0, parse_dates=True)
|
| 25 |
+
df.sort_index(inplace=True)
|
| 26 |
row_offset = offset_calculation(prediction_length, rolling_windows, len(df))
|
| 27 |
return plot_train_test(df.iloc[:row_offset], df.iloc[row_offset:])
|
| 28 |
|
| 29 |
|
| 30 |
+
def train_and_forecast(
|
| 31 |
+
input_data,
|
| 32 |
+
prediction_length,
|
| 33 |
+
rolling_windows,
|
| 34 |
+
epochs,
|
| 35 |
+
progress=gr.Progress(track_tqdm=True),
|
| 36 |
+
):
|
| 37 |
if not input_data:
|
| 38 |
raise gr.Error("Upload a file with the Upload button")
|
| 39 |
try:
|
| 40 |
df = pd.read_csv(input_data.name, index_col=0, parse_dates=True)
|
| 41 |
+
df.sort_index(inplace=True)
|
| 42 |
except AttributeError:
|
| 43 |
raise gr.Error("Upload a file with the Upload button")
|
| 44 |
|
| 45 |
row_offset = offset_calculation(prediction_length, rolling_windows, len(df))
|
| 46 |
|
| 47 |
+
try:
|
| 48 |
+
gluon_df = PandasDataset(df, target=df.columns[0])
|
| 49 |
+
except TypeError:
|
| 50 |
+
freq = pd.infer_freq(df.index[:3])
|
| 51 |
+
gluon_df = PandasDataset(df, target=df.columns[0], freq=freq)
|
| 52 |
|
| 53 |
training_data, test_gen = split(gluon_df, offset=row_offset)
|
| 54 |
|