Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -63,38 +63,40 @@ def get_next_row():
|
|
| 63 |
return row
|
| 64 |
return pd.DataFrame()
|
| 65 |
|
| 66 |
-
|
| 67 |
-
def
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
|
|
|
|
|
|
| 98 |
|
| 99 |
# Forecast ahead logic (5 steps, 30min intervals)
|
| 100 |
def forecast_next(df, model, steps=5):
|
|
|
|
| 63 |
return row
|
| 64 |
return pd.DataFrame()
|
| 65 |
|
| 66 |
+
|
| 67 |
+
def forecast_next(df, model, steps=5):
|
| 68 |
+
forecasts = []
|
| 69 |
+
df_copy = df.copy()
|
| 70 |
+
expected_features = model.feature_names_in_.tolist()
|
| 71 |
+
|
| 72 |
+
for i in range(steps):
|
| 73 |
+
df_copy = engineer(df_copy).dropna()
|
| 74 |
+
|
| 75 |
+
# Ensure all expected features are present
|
| 76 |
+
for col in expected_features:
|
| 77 |
+
if col not in df_copy.columns:
|
| 78 |
+
df_copy[col] = 0
|
| 79 |
+
|
| 80 |
+
# Select and order input features
|
| 81 |
+
input_row = df_copy.iloc[[-1]][expected_features]
|
| 82 |
+
|
| 83 |
+
y_pred = model.predict(input_row)[0]
|
| 84 |
+
|
| 85 |
+
# Prepare next row
|
| 86 |
+
next_timestamp = df_copy.iloc[-1]["timestamp"] + 1800
|
| 87 |
+
new_row = df_copy.iloc[-1].copy()
|
| 88 |
+
new_row["power_consumption_kwh"] = y_pred
|
| 89 |
+
new_row["timestamp"] = next_timestamp
|
| 90 |
+
|
| 91 |
+
df_copy = pd.concat([df_copy, pd.DataFrame([new_row])], ignore_index=True)
|
| 92 |
+
forecasts.append({"timestamp": next_timestamp, "forecast_kwh": y_pred})
|
| 93 |
+
|
| 94 |
+
return pd.DataFrame(forecasts)
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
|
| 100 |
|
| 101 |
# Forecast ahead logic (5 steps, 30min intervals)
|
| 102 |
def forecast_next(df, model, steps=5):
|