Spaces:
Running
Running
Commit ·
3305cc7
1
Parent(s): ed404c8
Atualizar uso de NaN em predição
Browse files- predict.py +14 -18
predict.py
CHANGED
|
@@ -9,6 +9,7 @@ import tensorflow as tf
|
|
| 9 |
import matplotlib.pyplot as plt
|
| 10 |
import base64
|
| 11 |
from io import BytesIO
|
|
|
|
| 12 |
|
| 13 |
warnings.filterwarnings('ignore')
|
| 14 |
plt.style.use('seaborn-v0_8-darkgrid')
|
|
@@ -101,6 +102,7 @@ class DenguePredictor:
|
|
| 101 |
for i in range(weeks_to_predict):
|
| 102 |
dynamic_input = np.array([dynamic_sequence_scaled], dtype=np.float32)
|
| 103 |
pred_scaled = self.model.predict([dynamic_input, static_input], verbose=0)[0][0]
|
|
|
|
| 104 |
pred_real = self.inverse_transform_cases(scaler_dyn, np.array([pred_scaled]))[0]
|
| 105 |
|
| 106 |
future_date = last_date + timedelta(weeks=i + 1)
|
|
@@ -109,25 +111,19 @@ class DenguePredictor:
|
|
| 109 |
"predicted_cases": max(0, round(pred_real))
|
| 110 |
})
|
| 111 |
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
target_year = last_year_date.year
|
| 116 |
-
if (target_year, target_week) in climate_lookup:
|
| 117 |
-
future_climate = climate_lookup[(target_year, target_week)]
|
| 118 |
else:
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
#
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
}
|
| 129 |
-
new_row_df = pd.DataFrame([new_row])[dynamic_features]
|
| 130 |
-
new_row_scaled = scaler_dyn.transform(new_row_df)[0]
|
| 131 |
dynamic_sequence_scaled = np.vstack([dynamic_sequence_scaled[1:], new_row_scaled])
|
| 132 |
|
| 133 |
# Histórico das últimas 52 semanas
|
|
|
|
| 9 |
import matplotlib.pyplot as plt
|
| 10 |
import base64
|
| 11 |
from io import BytesIO
|
| 12 |
+
import math
|
| 13 |
|
| 14 |
warnings.filterwarnings('ignore')
|
| 15 |
plt.style.use('seaborn-v0_8-darkgrid')
|
|
|
|
| 102 |
for i in range(weeks_to_predict):
|
| 103 |
dynamic_input = np.array([dynamic_sequence_scaled], dtype=np.float32)
|
| 104 |
pred_scaled = self.model.predict([dynamic_input, static_input], verbose=0)[0][0]
|
| 105 |
+
|
| 106 |
pred_real = self.inverse_transform_cases(scaler_dyn, np.array([pred_scaled]))[0]
|
| 107 |
|
| 108 |
future_date = last_date + timedelta(weeks=i + 1)
|
|
|
|
| 111 |
"predicted_cases": max(0, round(pred_real))
|
| 112 |
})
|
| 113 |
|
| 114 |
+
future_year, future_week = future_date.year, future_date.isocalendar()[1]
|
| 115 |
+
if (future_year, future_week) in climate_lookup:
|
| 116 |
+
future_climate = climate_lookup[(future_year, future_week)]
|
|
|
|
|
|
|
|
|
|
| 117 |
else:
|
| 118 |
+
future_climate = df_mun[dynamic_features[1:]].tail(4).mean() # só clima, sem numero_casos
|
| 119 |
+
|
| 120 |
+
new_row = np.zeros(len(dynamic_features), dtype=np.float32)
|
| 121 |
+
new_row[0] = pred_scaled # numero_casos previsto
|
| 122 |
+
for j, feat in enumerate(dynamic_features[1:], start=1):
|
| 123 |
+
new_row[j] = future_climate[feat]
|
| 124 |
+
|
| 125 |
+
# 6) Escala a linha futura e atualiza sequência
|
| 126 |
+
new_row_scaled = scaler_dyn.transform(new_row.reshape(1, -1))[0]
|
|
|
|
|
|
|
|
|
|
| 127 |
dynamic_sequence_scaled = np.vstack([dynamic_sequence_scaled[1:], new_row_scaled])
|
| 128 |
|
| 129 |
# Histórico das últimas 52 semanas
|