OnsAouedi commited on
Commit
7b75b81
·
verified ·
1 Parent(s): d3ff6e0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -10
app.py CHANGED
@@ -539,9 +539,18 @@ def classical_prediction(file_path, model_choice, min_mmsi, max_mmsi, models, lo
539
  last_lat_scaled, last_lon_scaled, scaler, lat_idx, lon_idx
540
  )
541
 
 
 
 
 
 
 
 
 
 
542
  # Calculate the classic evaluation metrics
543
- y_true_pairs = np.column_stack((true_lat.flatten(), true_lon.flatten()))
544
- y_pred_pairs = np.column_stack((pred_lat.flatten(), pred_lon.flatten()))
545
  classic_metrics = calculate_classic_metrics(y_true=y_true_pairs, y_pred=y_pred_pairs)
546
  classic_metrics['Inference Time (seconds)'] = inference_time # Include inference time
547
 
@@ -559,14 +568,14 @@ def classical_prediction(file_path, model_choice, min_mmsi, max_mmsi, models, lo
559
 
560
  # Prepare predicted and real positions DataFrame, including error in Km
561
  predicted_df = pd.DataFrame({
562
- 'MMSI': mmsi_seq[:len(y_pred)].flatten(),
563
- 'Last Known Latitude': last_lat_denorm.flatten(),
564
- 'Last Known Longitude': last_lon_denorm.flatten(),
565
- 'Predicted Latitude': pred_lat.flatten(),
566
- 'Predicted Longitude': pred_lon.flatten(),
567
- 'Real Latitude': true_lat.flatten(),
568
- 'Real Longitude': true_lon.flatten(),
569
- 'Error (Km)': error_km # Add the error in Km as a new column
570
  })
571
 
572
  # Save predictions as CSV
@@ -580,6 +589,7 @@ def classical_prediction(file_path, model_choice, min_mmsi, max_mmsi, models, lo
580
  logging.error(f"An error occurred: {str(e)}")
581
  return None, None, None, str(e)
582
 
 
583
  # ============================
584
  # Abnormal Behavior Detection
585
  # ============================
 
539
  last_lat_scaled, last_lon_scaled, scaler, lat_idx, lon_idx
540
  )
541
 
542
+ # Squeeze arrays to ensure they are 1-dimensional
543
+ pred_lat = pred_lat.squeeze()
544
+ pred_lon = pred_lon.squeeze()
545
+ true_lat = true_lat.squeeze()
546
+ true_lon = true_lon.squeeze()
547
+ last_lat_denorm = last_lat_denorm.squeeze()
548
+ last_lon_denorm = last_lon_denorm.squeeze()
549
+ mmsi_seq = mmsi_seq.squeeze()
550
+
551
  # Calculate the classic evaluation metrics
552
+ y_true_pairs = np.column_stack((true_lat, true_lon))
553
+ y_pred_pairs = np.column_stack((pred_lat, pred_lon))
554
  classic_metrics = calculate_classic_metrics(y_true=y_true_pairs, y_pred=y_pred_pairs)
555
  classic_metrics['Inference Time (seconds)'] = inference_time # Include inference time
556
 
 
568
 
569
  # Prepare predicted and real positions DataFrame, including error in Km
570
  predicted_df = pd.DataFrame({
571
+ 'MMSI': mmsi_seq[:len(y_pred)],
572
+ 'Last Known Latitude': last_lat_denorm,
573
+ 'Last Known Longitude': last_lon_denorm,
574
+ 'Predicted Latitude': pred_lat,
575
+ 'Predicted Longitude': pred_lon,
576
+ 'Real Latitude': true_lat,
577
+ 'Real Longitude': true_lon,
578
+ 'Error (Km)': error_km
579
  })
580
 
581
  # Save predictions as CSV
 
589
  logging.error(f"An error occurred: {str(e)}")
590
  return None, None, None, str(e)
591
 
592
+
593
  # ============================
594
  # Abnormal Behavior Detection
595
  # ============================