mirror of
https://github.com/NicolasBohn/NexQuant.git
synced 2026-08-07 03:57:45 +00:00
feat: Add ranking in kaggle scenario (#401)
* fix some bugs in rag * add ranking in kaggle scenario * fix two mistouches * fix two bugs * fix a bug
This commit is contained in:
@@ -148,6 +148,16 @@ class KGHypothesisExperiment2Feedback(HypothesisExperiment2Feedback):
|
|||||||
new_hypothesis = response_json.get("New Hypothesis", "No new hypothesis provided")
|
new_hypothesis = response_json.get("New Hypothesis", "No new hypothesis provided")
|
||||||
reason = response_json.get("Reasoning", "No reasoning provided")
|
reason = response_json.get("Reasoning", "No reasoning provided")
|
||||||
decision = convert2bool(response_json.get("Replace Best Result", "no"))
|
decision = convert2bool(response_json.get("Replace Best Result", "no"))
|
||||||
|
leaderboard = self.scen.leaderboard
|
||||||
|
current_score = current_result.iloc[0]
|
||||||
|
sorted_scores = sorted(leaderboard, reverse=True)
|
||||||
|
import bisect
|
||||||
|
|
||||||
|
if self.scen.evaluation_metric_direction:
|
||||||
|
insert_position = bisect.bisect_right([-score for score in sorted_scores], -current_score)
|
||||||
|
else:
|
||||||
|
insert_position = bisect.bisect_left(sorted_scores, current_score, lo=0, hi=len(sorted_scores))
|
||||||
|
percentile_ranking = (insert_position) / (len(sorted_scores)) * 100
|
||||||
|
|
||||||
experiment_feedback = {
|
experiment_feedback = {
|
||||||
"current_competition": self.scen.get_competition_full_desc(),
|
"current_competition": self.scen.get_competition_full_desc(),
|
||||||
@@ -158,6 +168,7 @@ class KGHypothesisExperiment2Feedback(HypothesisExperiment2Feedback):
|
|||||||
"observations": observations,
|
"observations": observations,
|
||||||
"hypothesis_evaluation": hypothesis_evaluation,
|
"hypothesis_evaluation": hypothesis_evaluation,
|
||||||
"reason": reason,
|
"reason": reason,
|
||||||
|
"percentile_ranking": percentile_ranking,
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.scen.if_using_vector_rag:
|
if self.scen.if_using_vector_rag:
|
||||||
|
|||||||
+1
-1
@@ -15,7 +15,7 @@ def fit(X_train: pd.DataFrame, y_train: pd.Series, X_valid: pd.DataFrame, y_vali
|
|||||||
Define and train the Random Forest model. Merge feature selection into the pipeline.
|
Define and train the Random Forest model. Merge feature selection into the pipeline.
|
||||||
"""
|
"""
|
||||||
# Initialize the Random Forest model
|
# Initialize the Random Forest model
|
||||||
model = RandomForestClassifier(n_estimators=100, random_state=32, n_jobs=-1)
|
model = RandomForestClassifier(n_estimators=200, random_state=32, n_jobs=-1)
|
||||||
|
|
||||||
# Fit the model
|
# Fit the model
|
||||||
model.fit(X_train, y_train)
|
model.fit(X_train, y_train)
|
||||||
|
|||||||
+1
-1
@@ -16,7 +16,7 @@ def fit(X_train: pd.DataFrame, y_train: pd.DataFrame, X_valid: pd.DataFrame, y_v
|
|||||||
"tree_method": "gpu_hist",
|
"tree_method": "gpu_hist",
|
||||||
"device": "cuda",
|
"device": "cuda",
|
||||||
}
|
}
|
||||||
num_round = 180
|
num_round = 200
|
||||||
|
|
||||||
evallist = [(dtrain, "train"), (dvalid, "eval")]
|
evallist = [(dtrain, "train"), (dvalid, "eval")]
|
||||||
bst = xgb.train(params, dtrain, num_round, evallist)
|
bst = xgb.train(params, dtrain, num_round, evallist)
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ for model, predict_func, select_m in model_l:
|
|||||||
metrics_all.append(metrics)
|
metrics_all.append(metrics)
|
||||||
|
|
||||||
# 5) Save the validation accuracy
|
# 5) Save the validation accuracy
|
||||||
min_index = np.argmin(metrics_all)
|
min_index = np.argmax(metrics_all)
|
||||||
pd.Series(data=[metrics_all[min_index]], index=["MCC"]).to_csv("submission_score.csv")
|
pd.Series(data=[metrics_all[min_index]], index=["MCC"]).to_csv("submission_score.csv")
|
||||||
|
|
||||||
# 6) Make predictions on the test set and save them
|
# 6) Make predictions on the test set and save them
|
||||||
|
|||||||
@@ -13,7 +13,10 @@ from rdagent.core.prompts import Prompts
|
|||||||
from rdagent.core.scenario import Scenario
|
from rdagent.core.scenario import Scenario
|
||||||
from rdagent.oai.llm_utils import APIBackend
|
from rdagent.oai.llm_utils import APIBackend
|
||||||
from rdagent.scenarios.kaggle.experiment.kaggle_experiment import KGFactorExperiment
|
from rdagent.scenarios.kaggle.experiment.kaggle_experiment import KGFactorExperiment
|
||||||
from rdagent.scenarios.kaggle.kaggle_crawler import crawl_descriptions
|
from rdagent.scenarios.kaggle.kaggle_crawler import (
|
||||||
|
crawl_descriptions,
|
||||||
|
leaderboard_scores,
|
||||||
|
)
|
||||||
from rdagent.scenarios.kaggle.knowledge_management.vector_base import (
|
from rdagent.scenarios.kaggle.knowledge_management.vector_base import (
|
||||||
KaggleExperienceBase,
|
KaggleExperienceBase,
|
||||||
)
|
)
|
||||||
@@ -72,6 +75,8 @@ class KGScenario(Scenario):
|
|||||||
self.confidence_parameter = 1.0
|
self.confidence_parameter = 1.0
|
||||||
self.initial_performance = 0.0
|
self.initial_performance = 0.0
|
||||||
|
|
||||||
|
self.leaderboard = leaderboard_scores(competition)
|
||||||
|
|
||||||
def _analysis_competition_description(self):
|
def _analysis_competition_description(self):
|
||||||
sys_prompt = (
|
sys_prompt = (
|
||||||
Environment(undefined=StrictUndefined)
|
Environment(undefined=StrictUndefined)
|
||||||
|
|||||||
@@ -87,6 +87,15 @@ def download_data(competition: str, local_path: str = "/data/userdata/share/kagg
|
|||||||
zip_ref.extractall(data_path)
|
zip_ref.extractall(data_path)
|
||||||
|
|
||||||
|
|
||||||
|
def leaderboard_scores(competition: str) -> list[float]:
|
||||||
|
from kaggle.api.kaggle_api_extended import KaggleApi
|
||||||
|
|
||||||
|
api = KaggleApi()
|
||||||
|
api.authenticate()
|
||||||
|
ll = api.competition_leaderboard_view(competition)
|
||||||
|
return [float(x.score) for x in ll]
|
||||||
|
|
||||||
|
|
||||||
def download_notebooks(
|
def download_notebooks(
|
||||||
competition: str, local_path: str = "/data/userdata/share/kaggle/notebooks", num: int = 15
|
competition: str, local_path: str = "/data/userdata/share/kaggle/notebooks", num: int = 15
|
||||||
) -> None:
|
) -> None:
|
||||||
@@ -254,15 +263,18 @@ if __name__ == "__main__":
|
|||||||
"facebook-v-predicting-check-ins",
|
"facebook-v-predicting-check-ins",
|
||||||
]
|
]
|
||||||
|
|
||||||
all_cs = mini_case_cs + other_cs
|
# all_cs = mini_case_cs + other_cs
|
||||||
for c in all_cs:
|
# for c in all_cs:
|
||||||
convert_notebooks_to_text(c)
|
# convert_notebooks_to_text(c)
|
||||||
exit()
|
# exit()
|
||||||
from kaggle.api.kaggle_api_extended import KaggleApi
|
# from kaggle.api.kaggle_api_extended import KaggleApi
|
||||||
|
|
||||||
api = KaggleApi()
|
# api = KaggleApi()
|
||||||
api.authenticate()
|
# api.authenticate()
|
||||||
cs = api.competitions_list()
|
# cs = api.competitions_list()
|
||||||
for c in cs:
|
# for c in cs:
|
||||||
name = c.ref.split("/")[-1]
|
# name = c.ref.split("/")[-1]
|
||||||
crawl_descriptions(name)
|
# crawl_descriptions(name)
|
||||||
|
res = leaderboard_scores(competition="playground-series-s4e8")
|
||||||
|
|
||||||
|
# %%
|
||||||
|
|||||||
@@ -217,6 +217,7 @@ class KGHypothesisGen(ModelHypothesisGen):
|
|||||||
# Select action with highest UCB
|
# Select action with highest UCB
|
||||||
selected_action = max(ucb_values, key=ucb_values.get)
|
selected_action = max(ucb_values, key=ucb_values.get)
|
||||||
self.scen.action_counts[selected_action] += 1
|
self.scen.action_counts[selected_action] += 1
|
||||||
|
|
||||||
return selected_action
|
return selected_action
|
||||||
|
|
||||||
def prepare_context(self, trace: Trace) -> Tuple[dict, bool]:
|
def prepare_context(self, trace: Trace) -> Tuple[dict, bool]:
|
||||||
@@ -336,6 +337,7 @@ class KGHypothesis2Experiment(ModelHypothesis2Experiment):
|
|||||||
raise ModelEmptyError(
|
raise ModelEmptyError(
|
||||||
f"Invalid model type '{model_type}'. Allowed model types are: {', '.join(KG_SELECT_MAPPING)}."
|
f"Invalid model type '{model_type}'. Allowed model types are: {', '.join(KG_SELECT_MAPPING)}."
|
||||||
)
|
)
|
||||||
|
|
||||||
tasks.append(
|
tasks.append(
|
||||||
ModelTask(
|
ModelTask(
|
||||||
name=response_dict.get("model_name", "Model name not provided"),
|
name=response_dict.get("model_name", "Model name not provided"),
|
||||||
|
|||||||
Reference in New Issue
Block a user