Skip to content

Commit

Permalink
Fix crash when script tried to write to non existing directory
Browse files Browse the repository at this point in the history
  • Loading branch information
KennethLj committed Jan 7, 2022
1 parent de80978 commit 37c10a5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 3 additions & 3 deletions example_model_advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from lightgbm import LGBMRegressor
import gc
from numerapi import NumerAPI
from utils import save_model, load_model, neutralize, get_biggest_change_features, validation_metrics, download_data, \
from utils import save_prediction, save_model, load_model, neutralize, get_biggest_change_features, validation_metrics, download_data, \
load_model_config, save_model_config, get_time_series_cross_val_splits


Expand Down Expand Up @@ -289,5 +289,5 @@
# rename best model to prediction and rank from 0 to 1 to meet diagnostic/submission file requirements
validation_data["prediction"] = validation_data[best_pred_col].rank(pct=True)
tournament_data["prediction"] = tournament_data[best_pred_col].rank(pct=True)
validation_data["prediction"].to_csv(f"prediction_files/validation_predictions_{current_round}.csv", index=True)
tournament_data["prediction"].to_csv(f"prediction_files/tournament_predictions_{current_round}.csv", index=True)
save_prediction(validation_data["prediction"], f"validation_predictions_{current_round}")
save_prediction(tournament_data["prediction"], f"tournament_predictions_{current_round}")
6 changes: 6 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
MODEL_CONFIGS_FOLDER = "model_configs"
PREDICTION_FILES_FOLDER = "prediction_files"

def save_prediction(df, name):
try:
Path(PREDICTION_FILES_FOLDER).mkdir(exist_ok=True, parents=True)
except Exception as ex:
pass
df.to_csv(f"{PREDICTION_FILES_FOLDER}/{name}", index=True)

def save_model(model, name):
try:
Expand Down

0 comments on commit 37c10a5

Please sign in to comment.