o1-preview-2024-09-12· OpenAI
WildChat-4.8M (AI2)
convert this into a fcuntion called evaultetestset where the sMAPE and MASE is…
- User
convert this into a fcuntion called evaulte_test_set where the sMAPE and MASE is calcaulted for each feature then averaged: I want the metrics without the plots
# Determine sizes n_features = len(feature_names) actual_len = len(actual_values) pred_len = len(predicted) # Adjust lengths to match min_len = min(actual_len, pred_len) actual_values = actual_values[-min_len:] predicted = predicted[-min_len:] print("After adjustment:") print("Actual values shape:", actual_values.shape) print("Predicted values shape:", predicted.shape) # Calculate number of rows and columns for subplots n_rows = (n_features + 1) // 2 n_cols = min(2, n_features) # Create figure plt.figure(figsize=(15, 5*n_rows)) # If num_points is not specified, use all available points if num_points is None: num_points = min_len end_idx = min(start_idx + num_points, min_len) if plotting: # Create a subplot for each feature for i in range(n_features): plt.subplot(n_rows, n_cols, i+1) # Extract feature data feature_actual = actual_values[start_idx:end_idx, i] feature_pred = predicted[start_idx:end_idx, i] # Ensure same length min_feature_len = min(len(feature_actual), len(feature_pred)) feature_actual = feature_actual[:min_feature_len] feature_pred = feature_pred[:min_feature_len] # Plot actual values plt.plot(feature_actual, label='Actual', color='blue', linestyle='-') # Plot predicted values plt.plot(feature_pred, label='Predicted', color='red', linestyle='--') plt.title(f'Feature: {feature_names[i]}') plt.xlabel('Time Steps') plt.ylabel('Value') plt.legend() plt.grid(True, alpha=0.3) # Calculate metrics # Metrics as defined by the M4 Competition try: smape_value = smape_np(feature_actual, feature_pred) mase_value = mase_np(feature_actual, feature_pred, actual_values[:, i]) # Using the full training series plt.text(0.02, 0.95, f'sMAPE: {smape_value:.3f}%\nMASE: {mase_value:.3f}', transform=plt.gca().transAxes, bbox=dict(facecolor='white', alpha=0.8)) except: print(f"Could not calculate metrics for feature {feature_names[i]}") - Assistant