Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -173,13 +173,19 @@ class CryptoAnalyzer:
|
|
| 173 |
model.eval()
|
| 174 |
with torch.no_grad():
|
| 175 |
predictions, confidence = model(X)
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
rmse = float(np.sqrt(np.mean((actual_prices - predictions) ** 2)))
|
| 181 |
mape = float(np.mean(np.abs((actual_prices - predictions) / actual_prices)) * 100)
|
| 182 |
r2 = float(1 - np.sum((actual_prices - predictions) ** 2) / np.sum((actual_prices - actual_prices.mean()) ** 2))
|
|
|
|
| 183 |
dates = df.index[lookback:].strftime('%Y-%m-%d').tolist()
|
| 184 |
return {
|
| 185 |
'dates': dates,
|
|
@@ -198,6 +204,7 @@ class CryptoAnalyzer:
|
|
| 198 |
except Exception as e:
|
| 199 |
raise ValueError(f"Prediction failed: {str(e)}")
|
| 200 |
|
|
|
|
| 201 |
def create_analysis_plots(symbol, days=180, lookback=30):
|
| 202 |
try:
|
| 203 |
analyzer = CryptoAnalyzer()
|
|
|
|
| 173 |
model.eval()
|
| 174 |
with torch.no_grad():
|
| 175 |
predictions, confidence = model(X)
|
| 176 |
+
|
| 177 |
+
# Fixing predictions and actual prices reshaping
|
| 178 |
+
predictions_reshaped = predictions.cpu().numpy().reshape(-1, 1)
|
| 179 |
+
predictions = self.price_scaler.inverse_transform(predictions_reshaped).flatten()
|
| 180 |
+
|
| 181 |
+
y_np_reshaped = y.cpu().numpy().reshape(-1, 1)
|
| 182 |
+
actual_prices = self.price_scaler.inverse_transform(y_np_reshaped).flatten()
|
| 183 |
+
|
| 184 |
+
# Metrics calculations
|
| 185 |
rmse = float(np.sqrt(np.mean((actual_prices - predictions) ** 2)))
|
| 186 |
mape = float(np.mean(np.abs((actual_prices - predictions) / actual_prices)) * 100)
|
| 187 |
r2 = float(1 - np.sum((actual_prices - predictions) ** 2) / np.sum((actual_prices - actual_prices.mean()) ** 2))
|
| 188 |
+
|
| 189 |
dates = df.index[lookback:].strftime('%Y-%m-%d').tolist()
|
| 190 |
return {
|
| 191 |
'dates': dates,
|
|
|
|
| 204 |
except Exception as e:
|
| 205 |
raise ValueError(f"Prediction failed: {str(e)}")
|
| 206 |
|
| 207 |
+
|
| 208 |
def create_analysis_plots(symbol, days=180, lookback=30):
|
| 209 |
try:
|
| 210 |
analyzer = CryptoAnalyzer()
|