{"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":true,"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:39:29.948153Z","iopub.execute_input":"2024-12-19T11:39:29.948629Z","iopub.status.idle":"2024-12-19T11:39:30.327243Z","shell.execute_reply.started":"2024-12-19T11:39:29.948595Z","shell.execute_reply":"2024-12-19T11:39:30.326131Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import polars as pl\nfrom sklearn.metrics import r2_score\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-19T11:39:30.328675Z","iopub.execute_input":"2024-12-19T11:39:30.328932Z","iopub.status.idle":"2024-12-19T11:39:30.333217Z","shell.execute_reply.started":"2024-12-19T11:39:30.328910Z","shell.execute_reply":"2024-12-19T11:39:30.332146Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import os\nimport numpy as np\nimport pandas as pd\nimport polars as pl\nfrom typing import Optional\nimport kaggle_evaluation.jane_street_inference_server","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-19T11:39:30.335171Z","iopub.execute_input":"2024-12-19T11:39:30.335461Z","iopub.status.idle":"2024-12-19T11:39:30.534114Z","shell.execute_reply.started":"2024-12-19T11:39:30.335436Z","shell.execute_reply":"2024-12-19T11:39:30.533178Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train=pl.scan_parquet(f\"/kaggle/input/20241219-data/training.parquet\").collect()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-19T11:39:30.535539Z","iopub.execute_input":"2024-12-19T11:39:30.536132Z","iopub.status.idle":"2024-12-19T11:39:34.121809Z","shell.execute_reply.started":"2024-12-19T11:39:30.536103Z","shell.execute_reply":"2024-12-19T11:39:34.120688Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train=train.to_pandas()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-19T11:39:34.122471Z","iopub.execute_input":"2024-12-19T11:39:34.122826Z","iopub.status.idle":"2024-12-19T11:39:41.975002Z","shell.execute_reply.started":"2024-12-19T11:39:34.122792Z","shell.execute_reply":"2024-12-19T11:39:41.970143Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"val=pl.scan_parquet(f\"/kaggle/input/20241219-data/validation.parquet\").collect()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-19T11:39:41.978085Z","iopub.execute_input":"2024-12-19T11:39:41.978695Z","iopub.status.idle":"2024-12-19T11:39:42.865765Z","shell.execute_reply.started":"2024-12-19T11:39:41.978666Z","shell.execute_reply":"2024-12-19T11:39:42.863792Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"val=val.to_pandas()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-19T11:39:42.869487Z","iopub.execute_input":"2024-12-19T11:39:42.870587Z","iopub.status.idle":"2024-12-19T11:39:43.257335Z","shell.execute_reply.started":"2024-12-19T11:39:42.870334Z","shell.execute_reply":"2024-12-19T11:39:43.256517Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-19T11:39:43.258339Z","iopub.execute_input":"2024-12-19T11:39:43.258751Z","iopub.status.idle":"2024-12-19T11:39:44.193721Z","shell.execute_reply.started":"2024-12-19T11:39:43.258716Z","shell.execute_reply":"2024-12-19T11:39:44.192774Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"val","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-19T11:39:44.196406Z","iopub.execute_input":"2024-12-19T11:39:44.196704Z","iopub.status.idle":"2024-12-19T11:39:44.351367Z","shell.execute_reply.started":"2024-12-19T11:39:44.196680Z","shell.execute_reply":"2024-12-19T11:39:44.350294Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train['responder_6'].median()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-19T11:39:44.353051Z","iopub.execute_input":"2024-12-19T11:39:44.353498Z","iopub.status.idle":"2024-12-19T11:39:44.469729Z","shell.execute_reply.started":"2024-12-19T11:39:44.353468Z","shell.execute_reply":"2024-12-19T11:39:44.468839Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"val['pred']=train['responder_6'].median()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-19T11:39:44.470854Z","iopub.execute_input":"2024-12-19T11:39:44.471237Z","iopub.status.idle":"2024-12-19T11:39:44.581399Z","shell.execute_reply.started":"2024-12-19T11:39:44.471198Z","shell.execute_reply":"2024-12-19T11:39:44.580440Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"r2 = r2_score(val['responder_6'],val['pred'])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-19T11:39:44.582457Z","iopub.execute_input":"2024-12-19T11:39:44.582733Z","iopub.status.idle":"2024-12-19T11:39:44.592355Z","shell.execute_reply.started":"2024-12-19T11:39:44.582708Z","shell.execute_reply":"2024-12-19T11:39:44.591405Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"r2","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-19T11:39:44.593179Z","iopub.execute_input":"2024-12-19T11:39:44.593549Z","iopub.status.idle":"2024-12-19T11:39:44.603915Z","shell.execute_reply.started":"2024-12-19T11:39:44.593518Z","shell.execute_reply":"2024-12-19T11:39:44.602854Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def predict(test: pl.DataFrame, lags: Optional[pl.DataFrame] = None) -> pl.DataFrame:\n    \"\"\"\n    Simple prediction function for time series competition.\n    \n    Args:\n        test (pl.DataFrame): Current test data\n        lags (pl.DataFrame, optional): Historical lag data\n    \n    Returns:\n        pl.DataFrame: Predictions for responder_6\n    \"\"\"\n    # Ensure required columns exist\n    required_columns = ['row_id', 'date_id', 'time_id', 'symbol_id']\n    for col in required_columns:\n        if col not in test.columns:\n            raise ValueError(f\"Missing required column: {col}\")\n    \n    # If lags exist, compute mean of responder_6\n    if lags is not None and 'responder_6' in lags.columns:\n        historical_median = lags['responder_6'].median()\n    else:\n        historical_median = 0.0\n    \n    # Generate predictions (with small noise for randomness)\n    predictions = test.with_columns([\n        pl.lit(historical_median + np.random.normal(0, 0.1)).alias('responder_6')\n    ])\n    print(predictions.select(['row_id', 'responder_6']))\n    return predictions.select(['row_id', 'responder_6'])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-19T11:39:44.604996Z","iopub.execute_input":"2024-12-19T11:39:44.605353Z","iopub.status.idle":"2024-12-19T11:39:44.618886Z","shell.execute_reply.started":"2024-12-19T11:39:44.605319Z","shell.execute_reply":"2024-12-19T11:39:44.617761Z"}},"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:44.620081Z","iopub.execute_input":"2024-12-19T11:39:44.620547Z","iopub.status.idle":"2024-12-19T11:39:44.839895Z","shell.execute_reply.started":"2024-12-19T11:39:44.620509Z","shell.execute_reply":"2024-12-19T11:39:44.838760Z"}},"outputs":[],"execution_count":null}]}