Spaces:
Sleeping
Sleeping
Bachstelze commited on
Commit ·
de7924c
1
Parent(s): 76e50c6
save plot figure
Browse files2 unmodified lines3456789101112131415161718192021222324252627282930313226 unmodified lines5960614243626364656634 unmodified lines1011021031041051061071081091102 unmodified linesfrom sklearn.linear_model import LinearRegressionfrom sklearn.metrics import mean_absolute_error, r2_scoreimport re # For using regular expressionsimport matplotlib.pyplot as pltimport datetime
train_path = "../Datasets_all/A2_dataset_80.csv"test_path = "../Datasets_all/A2_dataset_20.csv"
def save_prediction_plot(y_test, y_test_pred_baseline, baseline_test_r2): # Visualize baseline predictions fig, axes = plt.subplots(figsize=(5, 5))
# Actual vs Predicted axes.scatter(y_test, y_test_pred_baseline, alpha=0.5) axes.plot([y_test.min(), y_test.max()], [y_test.min(), y_test.max()], 'r--', lw=2) axes.set_xlabel('Actual AimoScore') axes.set_ylabel('Predicted AimoScore') axes.set_title(f'Baseline: Actual vs Predicted (R²={baseline_test_r2:.4f})') axes.grid(True, alpha=0.3)
# Save the figure timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S") # e.g., 20260130_143210 fig_path = f"baseline_actual_vs_predicted_{timestamp}.png" plt.savefig(fig_path, dpi=300, bbox_inches='tight') print(f"Figure saved to {fig_path}")
def extract_missing_feature(error_message): # Use regex to find feature names in the ValueError message match = re.search(r"Feature names unseen at fit time:\s*-\s*(.+)", error_message)26 unmodified lines X_test = test_df[features_cols] y_test = test_df[target_col]
#define y_pred y_pred = 0 #define y_pred and r2 y_pred, r2 = 0, 0
# Continue to predict until no ValueErrors occur while True:34 unmodified lines # Save predictions to CSV test_df["Predicted_AimoScore"] = y_pred test_df.to_csv("predicted_test.csv", index=False) else: print("no predictions!!!")
save_prediction_plot(y_test, y_pred, r2)
if __name__ == "__main__":test/test_model.py+26-2