From af9582a0a75fa3e73589593e54094a9b154763ed Mon Sep 17 00:00:00 2001 From: Xu Yang Date: Thu, 3 Apr 2025 09:48:38 -0600 Subject: [PATCH] fix when score is a string (#750) --- .../proposal/exp_gen/prompts_v2.yaml | 2 +- .../data_science/proposal/exp_gen/proposal.py | 23 +++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/rdagent/scenarios/data_science/proposal/exp_gen/prompts_v2.yaml b/rdagent/scenarios/data_science/proposal/exp_gen/prompts_v2.yaml index 183bca21..69f5174f 100644 --- a/rdagent/scenarios/data_science/proposal/exp_gen/prompts_v2.yaml +++ b/rdagent/scenarios/data_science/proposal/exp_gen/prompts_v2.yaml @@ -200,7 +200,7 @@ output_format: hypothesis: |- For each of the identified problem, you should propose a hypothesis strictly following to the JSON schema. Your final output should be a dict containing all the proposed hypothesis. { - "problem name 1": { + "problem name 1 (Should be exactly same as the problem name provided)": { "reason": "Provide a clear, logical progression from problem identification to hypothesis formulation, grounded in evidence (e.g., trace history, domain principles, or competition constraints). Refer to the Hypothesis Guidelines for better understanding. Reason should be short with no more than two sentences.", {% if not pipeline %}"component": "The component name that the hypothesis focus on. Must be one of ('DataLoadSpec', 'FeatureEng', 'Model', 'Ensemble', 'Workflow').", {% else %}"component": "The component name that the hypothesis focus on. Must be 'Pipeline'.", diff --git a/rdagent/scenarios/data_science/proposal/exp_gen/proposal.py b/rdagent/scenarios/data_science/proposal/exp_gen/proposal.py index b1130eb1..92cef4fd 100644 --- a/rdagent/scenarios/data_science/proposal/exp_gen/proposal.py +++ b/rdagent/scenarios/data_science/proposal/exp_gen/proposal.py @@ -326,15 +326,20 @@ class DSProposalV2ExpGen(ExpGen): "feasibility_score": 0.1, "risk_reward_balance_score": 0.1, } - scores = pd.DataFrame( - { - problem_name: { - score_key: hypothesis_dict[problem_name]["evaluation"].get(score_key, 0) * weight - for score_key, weight in weights.items() - } - for problem_name in hypothesis_dict - } - ) + scores_dict = {} + for problem_name in hypothesis_dict: + scores_dict[problem_name] = {} + for score_key in weights: + if score_key not in hypothesis_dict[problem_name]["evaluation"]: + scores_dict[problem_name][score_key] = 0 + else: + try: + scores_dict[problem_name][score_key] = ( + float(hypothesis_dict[problem_name]["evaluation"][score_key]) * weights[score_key] + ) + except (ValueError, TypeError): + scores_dict[problem_name][score_key] = 0 + scores = pd.DataFrame(scores_dict) scores_sorted = scores.sum().sort_values(ascending=False) if len(scores_sorted) > 5: scores_sorted = scores_sorted[: len(scores_sorted) // 2]