{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","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":10245336,"sourceType":"datasetVersion","datasetId":6336300}],"dockerImageVersionId":30822,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2024-12-19T11:30:22.225837Z","iopub.execute_input":"2024-12-19T11:30:22.226276Z","iopub.status.idle":"2024-12-19T11:30:23.154911Z","shell.execute_reply.started":"2024-12-19T11:30:22.226217Z","shell.execute_reply":"2024-12-19T11:30:23.153837Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import polars as pl\nfrom sklearn.metrics import r2_score\nimport pandas as pd\nimport kaggle_evaluation.jane_street_inference_server","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-19T11:38:38.528416Z","iopub.execute_input":"2024-12-19T11:38:38.528803Z","iopub.status.idle":"2024-12-19T11:38:38.732346Z","shell.execute_reply.started":"2024-12-19T11:38:38.528775Z","shell.execute_reply":"2024-12-19T11:38:38.731374Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train=pl.scan_parquet(\n    f\"/kaggle/input/20241219-data/training.parquet\"\n).collect()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-19T11:31:17.096085Z","iopub.execute_input":"2024-12-19T11:31:17.096479Z","iopub.status.idle":"2024-12-19T11:31:21.228188Z","shell.execute_reply.started":"2024-12-19T11:31:17.096445Z","shell.execute_reply":"2024-12-19T11:31:21.227155Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train=train.to_pandas()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-19T11:31:24.942828Z","iopub.execute_input":"2024-12-19T11:31:24.943146Z","iopub.status.idle":"2024-12-19T11:31:35.440523Z","shell.execute_reply.started":"2024-12-19T11:31:24.943122Z","shell.execute_reply":"2024-12-19T11:31:35.436746Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"val=pl.scan_parquet(\n    f\"/kaggle/input/20241219-data/validation.parquet\"\n).collect()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-19T11:31:35.445317Z","iopub.execute_input":"2024-12-19T11:31:35.446412Z","iopub.status.idle":"2024-12-19T11:31:36.178156Z","shell.execute_reply.started":"2024-12-19T11:31:35.446296Z","shell.execute_reply":"2024-12-19T11:31:36.175386Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"val=val.to_pandas","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-19T11:31:37.301096Z","iopub.execute_input":"2024-12-19T11:31:37.302109Z","iopub.status.idle":"2024-12-19T11:31:37.315832Z","shell.execute_reply.started":"2024-12-19T11:31:37.301983Z","shell.execute_reply":"2024-12-19T11:31:37.311979Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"val","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-19T11:31:41.646512Z","iopub.execute_input":"2024-12-19T11:31:41.646894Z","iopub.status.idle":"2024-12-19T11:31:41.662037Z","shell.execute_reply.started":"2024-12-19T11:31:41.646863Z","shell.execute_reply":"2024-12-19T11:31:41.660949Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-19T11:33:36.836557Z","iopub.execute_input":"2024-12-19T11:33:36.837455Z","iopub.status.idle":"2024-12-19T11:33:38.509438Z","shell.execute_reply.started":"2024-12-19T11:33:36.837414Z","shell.execute_reply":"2024-12-19T11:33:38.508277Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train['responder_6_lag_1'].median()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-19T11:36:27.138350Z","iopub.execute_input":"2024-12-19T11:36:27.138717Z","iopub.status.idle":"2024-12-19T11:36:27.268642Z","shell.execute_reply.started":"2024-12-19T11:36:27.138687Z","shell.execute_reply":"2024-12-19T11:36:27.267490Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"lags_ : pl.DataFrame | None = None\n\n\n# Replace this function with your inference code.\n# You can return either a Pandas or Polars dataframe, though Polars is recommended.\n# Each batch of predictions (except the very first) must be returned within 1 minute of the batch features being provided.\ndef predict(test: pl.DataFrame, lags: pl.DataFrame | None) -> pl.DataFrame | pd.DataFrame:\n    \"\"\"Make a prediction.\"\"\"\n    # All the responders from the previous day are passed in at time_id == 0. We save them in a global variable for access at every time_id.\n    # Use them as extra features, if you like.\n    global lags_\n    if lags is not None:\n        lags_ = lags\n\n    # Replace this section with your own predictions\n    predictions = test.select(\n        'row_id',\n        pl.lit(-0.012151758).alias('responder_6'),\n    )\n\n    if isinstance(predictions, pl.DataFrame):\n        assert predictions.columns == ['row_id', 'responder_6']\n    elif isinstance(predictions, pd.DataFrame):\n        assert (predictions.columns == ['row_id', 'responder_6']).all()\n    else:\n        raise TypeError('The predict function must return a DataFrame')\n    # Confirm has as many rows as the test data.\n    assert len(predictions) == len(test)\n\n    return predictions","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-19T11:37:31.446470Z","iopub.execute_input":"2024-12-19T11:37:31.446929Z","iopub.status.idle":"2024-12-19T11:37:31.455748Z","shell.execute_reply.started":"2024-12-19T11:37:31.446893Z","shell.execute_reply":"2024-12-19T11:37:31.454379Z"}},"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-19T11:38:43.168554Z","iopub.execute_input":"2024-12-19T11:38:43.169161Z","iopub.status.idle":"2024-12-19T11:38:43.397151Z","shell.execute_reply.started":"2024-12-19T11:38:43.169127Z","shell.execute_reply":"2024-12-19T11:38:43.395974Z"}},"outputs":[],"execution_count":null}]}