{"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"}],"dockerImageVersionId":30804,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import os\n\nimport polars as pl\n\nimport kaggle_evaluation.jane_street_inference_server","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2024-12-14T21:57:39.287883Z","iopub.execute_input":"2024-12-14T21:57:39.288453Z","iopub.status.idle":"2024-12-14T21:57:40.276557Z","shell.execute_reply.started":"2024-12-14T21:57:39.288367Z","shell.execute_reply":"2024-12-14T21:57:40.275169Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"lags_: pl.DataFrame | None = None\n\ndef predict(test: pl.DataFrame, lags: pl.DataFrame | None) -> pl.DataFrame:\n    \"\"\"Make a prediction by matching test data with lagged values.\"\"\"\n    global lags_\n    if lags is not None:\n        lags_ = lags\n    \n    predictions = (\n        test\n        .join(\n            lags_\n            .select(['date_id', 'time_id', 'symbol_id', 'responder_6_lag_1']),\n            on=[\"date_id\", \"time_id\", \"symbol_id\"],\n            how=\"left\"\n        )\n        .with_columns(\n            pl.col('responder_6_lag_1')\n            .fill_null(0)\n            .alias('responder_6')\n            .cast(pl.Float64)\n        )\n        .select(['row_id', 'responder_6'])\n    )\n\n    assert predictions.columns == ['row_id', 'responder_6']\n    assert len(predictions) == len(test), \\\n        f\"Predictions length ({len(predictions)}) doesn't match test length ({len(test)})\"\n\n    return predictions","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-14T21:57:40.278953Z","iopub.execute_input":"2024-12-14T21:57:40.279631Z","iopub.status.idle":"2024-12-14T21:57:40.287938Z","shell.execute_reply.started":"2024-12-14T21:57:40.279581Z","shell.execute_reply":"2024-12-14T21:57:40.286811Z"}},"outputs":[],"execution_count":null},{"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":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-14T21:57:40.289381Z","iopub.execute_input":"2024-12-14T21:57:40.289775Z","iopub.status.idle":"2024-12-14T21:57:40.692328Z","shell.execute_reply.started":"2024-12-14T21:57:40.289736Z","shell.execute_reply":"2024-12-14T21:57:40.691185Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# test = pl.read_parquet('/kaggle/input/jane-street-real-time-market-data-forecasting/test.parquet')\n# lags = pl.read_parquet('/kaggle/input/jane-street-real-time-market-data-forecasting/lags.parquet')\n# predict(test, lags)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-14T21:57:40.695037Z","iopub.execute_input":"2024-12-14T21:57:40.695544Z","iopub.status.idle":"2024-12-14T21:57:40.723150Z","shell.execute_reply.started":"2024-12-14T21:57:40.695490Z","shell.execute_reply":"2024-12-14T21:57:40.721929Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# lags","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-14T21:57:40.724576Z","iopub.execute_input":"2024-12-14T21:57:40.724914Z","iopub.status.idle":"2024-12-14T21:57:40.735821Z","shell.execute_reply.started":"2024-12-14T21:57:40.724874Z","shell.execute_reply":"2024-12-14T21:57:40.734678Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# test","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-14T21:57:40.737163Z","iopub.execute_input":"2024-12-14T21:57:40.737532Z","iopub.status.idle":"2024-12-14T21:57:40.767355Z","shell.execute_reply.started":"2024-12-14T21:57:40.737496Z","shell.execute_reply":"2024-12-14T21:57:40.765704Z"}},"outputs":[],"execution_count":null}]}