{"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:49.154240Z","iopub.execute_input":"2024-12-19T11:30:49.154661Z","iopub.status.idle":"2024-12-19T11:30:49.507708Z","shell.execute_reply.started":"2024-12-19T11:30:49.154627Z","shell.execute_reply":"2024-12-19T11:30:49.506535Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import polars as pl\nfrom sklearn.metrics import r2_score\nimport pandas as pd","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-19T11:30:49.509079Z","iopub.execute_input":"2024-12-19T11:30:49.509456Z","iopub.status.idle":"2024-12-19T11:30:49.514942Z","shell.execute_reply.started":"2024-12-19T11:30:49.509428Z","shell.execute_reply":"2024-12-19T11:30:49.513860Z"}},"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:30:49.516908Z","iopub.execute_input":"2024-12-19T11:30:49.517241Z","iopub.status.idle":"2024-12-19T11:30:52.643227Z","shell.execute_reply.started":"2024-12-19T11:30:49.517213Z","shell.execute_reply":"2024-12-19T11:30:52.641884Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train=train.to_pandas()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-19T11:30:52.644707Z","iopub.execute_input":"2024-12-19T11:30:52.645008Z","iopub.status.idle":"2024-12-19T11:31:00.031403Z","shell.execute_reply.started":"2024-12-19T11:30:52.644981Z","shell.execute_reply":"2024-12-19T11:31:00.030149Z"}},"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:00.033133Z","iopub.execute_input":"2024-12-19T11:31:00.033681Z","iopub.status.idle":"2024-12-19T11:31:00.619802Z","shell.execute_reply.started":"2024-12-19T11:31:00.033575Z","shell.execute_reply":"2024-12-19T11:31:00.617307Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"val=val.to_pandas()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-19T11:31:00.621203Z","iopub.execute_input":"2024-12-19T11:31:00.621696Z","iopub.status.idle":"2024-12-19T11:31:01.811515Z","shell.execute_reply.started":"2024-12-19T11:31:00.621649Z","shell.execute_reply":"2024-12-19T11:31:01.810013Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"val.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-19T11:31:01.813936Z","iopub.execute_input":"2024-12-19T11:31:01.814472Z","iopub.status.idle":"2024-12-19T11:31:01.883819Z","shell.execute_reply.started":"2024-12-19T11:31:01.814419Z","shell.execute_reply":"2024-12-19T11:31:01.882309Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-19T11:34:25.548282Z","iopub.execute_input":"2024-12-19T11:34:25.548635Z","iopub.status.idle":"2024-12-19T11:34:26.637449Z","shell.execute_reply.started":"2024-12-19T11:34:25.548606Z","shell.execute_reply":"2024-12-19T11:34:26.636062Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"median_value = train['responder_6_lag_1'].median()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-19T11:36:49.885244Z","iopub.execute_input":"2024-12-19T11:36:49.885591Z","iopub.status.idle":"2024-12-19T11:36:50.013940Z","shell.execute_reply.started":"2024-12-19T11:36:49.885565Z","shell.execute_reply":"2024-12-19T11:36:50.012480Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"median_value","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-19T11:37:21.573368Z","iopub.execute_input":"2024-12-19T11:37:21.573858Z","iopub.status.idle":"2024-12-19T11:37:21.581330Z","shell.execute_reply.started":"2024-12-19T11:37:21.573822Z","shell.execute_reply":"2024-12-19T11:37:21.580167Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import kaggle_evaluation.jane_street_inference_server","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-19T11:38:46.726051Z","iopub.execute_input":"2024-12-19T11:38:46.726434Z","iopub.status.idle":"2024-12-19T11:38:46.992245Z","shell.execute_reply.started":"2024-12-19T11:38:46.726405Z","shell.execute_reply":"2024-12-19T11:38:46.991244Z"}},"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:39:17.677683Z","iopub.execute_input":"2024-12-19T11:39:17.678045Z","iopub.status.idle":"2024-12-19T11:39:17.684925Z","shell.execute_reply.started":"2024-12-19T11:39:17.678017Z","shell.execute_reply":"2024-12-19T11:39:17.683753Z"}},"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:39:21.241989Z","iopub.execute_input":"2024-12-19T11:39:21.242377Z","iopub.status.idle":"2024-12-19T11:39:21.278834Z","shell.execute_reply.started":"2024-12-19T11:39:21.242347Z","shell.execute_reply":"2024-12-19T11:39:21.277594Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}