Spaces:
Sleeping
Sleeping
Bachstelze commited on
Commit ·
de7924c
1
Parent(s): 76e50c6
save plot figure
Browse files2 unmodified lines345678910111226 unmodified lines394041424344454634 unmodified lines8182838485862 unmodified linesfrom sklearn.linear_model import LinearRegressionfrom sklearn.metrics import mean_absolute_error, r2_scoreimport re # For using regular expressionstrain_path = "../Datasets_all/A2_dataset_80.csv"test_path = "../Datasets_all/A2_dataset_20.csv"def extract_missing_feature(error_message):# Use regex to find feature names in the ValueError messagematch = re.search(r"Feature names unseen at fit time:\s*-\s*(.+)", error_message)26 unmodified linesX_test = test_df[features_cols]y_test = test_df[target_col]#define y_predy_pred = 0# Continue to predict until no ValueErrors occurwhile True:34 unmodified lines# Save predictions to CSVtest_df["Predicted_AimoScore"] = y_predtest_df.to_csv("predicted_test.csv", index=False)if __name__ == "__main__":2 unmodified lines3456789101112131415161718192021222324252627282930313226 unmodified lines596061626364656634 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 datetimetrain_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 predictionsfig, axes = plt.subplots(figsize=(5, 5))# Actual vs Predictedaxes.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 figuretimestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S") # e.g., 20260130_143210fig_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 messagematch = re.search(r"Feature names unseen at fit time:\s*-\s*(.+)", error_message)26 unmodified linesX_test = test_df[features_cols]y_test = test_df[target_col]#define y_pred and r2y_pred, r2 = 0, 0# Continue to predict until no ValueErrors occurwhile True:34 unmodified lines# Save predictions to CSVtest_df["Predicted_AimoScore"] = y_predtest_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