mirror of
https://github.com/NicolasBohn/NexQuant.git
synced 2026-08-06 11:37:44 +00:00
732361bb90
- Path injection (B614): centralized safe_resolve_path in core/utils.py, refactored 6 UI modules to use it with safe_root validation - B701: added explicit autoescape=select_autoescape() to Jinja2 Environment() calls in 3 files - B101: replaced assert statements with proper if/raise patterns in 12+ files (partial) - B112: added logger.warning() to bare except:continue blocks in 5 files
44 lines
1.5 KiB
Python
44 lines
1.5 KiB
Python
from pathlib import Path
|
|
|
|
import pandas as pd
|
|
from sklearn.model_selection import train_test_split
|
|
|
|
|
|
def prepare(raw: Path, public: Path, private: Path):
|
|
|
|
# Create train and test splits from train set
|
|
old_train = pd.read_csv(raw / "train.csv")
|
|
new_train, new_test = train_test_split(old_train, test_size=0.1, random_state=0)
|
|
|
|
# Create sample submission
|
|
sample_submission = new_test.copy()
|
|
sample_submission["price"] = 43878.016
|
|
sample_submission.drop(sample_submission.columns.difference(["id", "price"]), axis=1, inplace=True)
|
|
sample_submission.to_csv(public / "sample_submission.csv", index=False)
|
|
|
|
# Create private files
|
|
new_test.to_csv(private / "submission_test.csv", index=False)
|
|
|
|
# Create public files visible to agents
|
|
new_train.to_csv(public / "train.csv", index=False)
|
|
new_test.drop(["price"], axis=1, inplace=True)
|
|
new_test.to_csv(public / "test.csv", index=False)
|
|
|
|
# Checks
|
|
if new_test.shape[1] != 12:
|
|
raise AssertionError("Public test set should have 12 columns")
|
|
if new_train.shape[1] != 13:
|
|
raise AssertionError("Public train set should have 13 columns")
|
|
if len(new_train) + len(new_test) != len(old_train):
|
|
raise AssertionError("Length of new_train and new_test should equal length of old_train")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
competitions = "playground-series-s4e9"
|
|
raw = Path(__file__).resolve().parent
|
|
prepare(
|
|
raw=raw,
|
|
public=raw.parent.parent / competitions,
|
|
private=raw.parent.parent / "eval" / competitions,
|
|
)
|