{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.14","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":84493,"databundleVersionId":9871156,"sourceType":"competition"},{"sourceId":9900707,"sourceType":"datasetVersion","datasetId":6081837}],"dockerImageVersionId":30786,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np  # linear algebra\nimport pandas as pd\nimport polars as pl\n\n# plotting stuff\nfrom pandas.plotting import lag_plot\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport plotly.express as px\nimport plotly.graph_objects as go\n# system\nimport warnings\n\nwarnings.filterwarnings('ignore')\n# for the image import\n\nfrom IPython.display import Image\n# garbage collector to keep RAM in check\nimport gc\nimport os\nfrom tqdm import tqdm\nimport lightgbm as lgb\n# import xgboost as xgb\nimport catboost as cbt\nimport pickle as pkl\n\nimport kaggle_evaluation.jane_street_inference_server","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-11-14T03:54:29.027238Z","iopub.execute_input":"2024-11-14T03:54:29.027805Z","iopub.status.idle":"2024-11-14T03:54:35.042720Z","shell.execute_reply.started":"2024-11-14T03:54:29.027736Z","shell.execute_reply":"2024-11-14T03:54:35.041550Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_dir = '/kaggle/input/jane-street-2024-ml-model'\n\nwith open(os.path.join(model_dir, 'lgb_v1.bin'), 'rb') as fin:\n    lgb_model = pkl.load(fin)\nlgb_model","metadata":{"execution":{"iopub.status.busy":"2024-11-14T04:00:30.661100Z","iopub.execute_input":"2024-11-14T04:00:30.662257Z","iopub.status.idle":"2024-11-14T04:00:30.682192Z","shell.execute_reply.started":"2024-11-14T04:00:30.662202Z","shell.execute_reply":"2024-11-14T04:00:30.681117Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"feature_cols = ['feature_{:02d}'.format(i) for i in range(79)] + ['symbol_id']\nfeature_cols[:10]","metadata":{"execution":{"iopub.status.busy":"2024-11-14T04:00:40.107558Z","iopub.execute_input":"2024-11-14T04:00:40.108054Z","iopub.status.idle":"2024-11-14T04:00:40.116984Z","shell.execute_reply.started":"2024-11-14T04:00:40.108011Z","shell.execute_reply":"2024-11-14T04:00:40.115753Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lags_: pl.DataFrame | None = None\ndef predict(test: pl.DataFrame, lags: pl.DataFrame | None) -> pl.DataFrame:\n    global lags_, lgb_model, feature_cols\n    \n    # Logic for saving or loading lags\n    if lags is not None:\n        lags_ = lags\n    \n    test = test.to_pandas()\n    test_df = test[feature_cols].values\n    predictions = lgb_model.predict(test_df)\n\n    output_df = pd.DataFrame({\"row_id\": test['row_id'], \"responder_6\": predictions})\n\n        \n    return pl.from_pandas(output_df)","metadata":{"execution":{"iopub.status.busy":"2024-11-14T03:59:49.699029Z","iopub.execute_input":"2024-11-14T03:59:49.699976Z","iopub.status.idle":"2024-11-14T03:59:49.707367Z","shell.execute_reply.started":"2024-11-14T03:59:49.699925Z","shell.execute_reply":"2024-11-14T03:59:49.706186Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"inference_server = kaggle_evaluation.jane_street_inference_server.JSInferenceServer(predict)\n\nif os.getenv('KAGGLE_IS_COMPETITION_RERUN'):\n    inference_server.serve()\nelse:\n    inference_server.run_local_gateway(\n        (\n            '/kaggle/input/jane-street-real-time-market-data-forecasting/test.parquet',\n            '/kaggle/input/jane-street-real-time-market-data-forecasting/lags.parquet',\n        )\n    )","metadata":{"execution":{"iopub.status.busy":"2024-11-14T04:02:25.380414Z","iopub.execute_input":"2024-11-14T04:02:25.380878Z","iopub.status.idle":"2024-11-14T04:02:25.664181Z","shell.execute_reply.started":"2024-11-14T04:02:25.380835Z","shell.execute_reply":"2024-11-14T04:02:25.662687Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}