{"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"}],"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":"2025-01-12T22:52:36.062482Z","iopub.execute_input":"2025-01-12T22:52:36.063463Z","iopub.status.idle":"2025-01-12T22:52:36.141780Z","shell.execute_reply.started":"2025-01-12T22:52:36.063421Z","shell.execute_reply":"2025-01-12T22:52:36.140613Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"\ntarget_col = \"responder_6\"\nnecessary_cols = [target_col, 'weight']\nfeat_clear_categ = [\"feature_09\", \"feature_10\", \"feature_11\"]\nfeature_categ = feat_clear_categ + ['symbol_id', 'time_id']\nfeature_cols = [f\"feature_{idx:02d}\" for idx in range(79) if idx not in [9, 10, 11, 61]]\nresponder_cols = [f\"responder_{idx}_lag_1\" for idx in range(9)] \nfeature_cont = feature_cols + responder_cols\ndataset_cols = feature_cont + necessary_cols + feature_categ\nstd_feature = [i for i in feature_cont]\n\nbatch_size = 8192\nn_cont_features = len(feature_cont)\nn_cat_features = len(feature_categ)\nn_classes = None\ncat_cardinalities = [23, 10, 32, 40, 969]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-12T16:46:35.619233Z","iopub.execute_input":"2025-01-12T16:46:35.619588Z","iopub.status.idle":"2025-01-12T16:46:35.626478Z","shell.execute_reply.started":"2025-01-12T16:46:35.619550Z","shell.execute_reply":"2025-01-12T16:46:35.625505Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import pandas as pd","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-12T17:54:32.887353Z","iopub.execute_input":"2025-01-12T17:54:32.887682Z","iopub.status.idle":"2025-01-12T17:54:32.891864Z","shell.execute_reply.started":"2025-01-12T17:54:32.887653Z","shell.execute_reply":"2025-01-12T17:54:32.890741Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"path = f\"/kaggle/input/jane-street-real-time-market-data-forecasting/train.parquet/partition_id=1/part-0.parquet\"\ndf = pd.read_parquet(path)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-12T19:36:29.493825Z","iopub.execute_input":"2025-01-12T19:36:29.494664Z","iopub.status.idle":"2025-01-12T19:36:31.991390Z","shell.execute_reply.started":"2025-01-12T19:36:29.494607Z","shell.execute_reply":"2025-01-12T19:36:31.990325Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-12T17:54:48.973112Z","iopub.execute_input":"2025-01-12T17:54:48.973436Z","iopub.status.idle":"2025-01-12T17:54:49.010509Z","shell.execute_reply.started":"2025-01-12T17:54:48.973411Z","shell.execute_reply":"2025-01-12T17:54:49.009396Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df[feature_cols]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-12T17:59:05.181774Z","iopub.execute_input":"2025-01-12T17:59:05.182126Z","iopub.status.idle":"2025-01-12T17:59:06.120574Z","shell.execute_reply.started":"2025-01-12T17:59:05.182099Z","shell.execute_reply":"2025-01-12T17:59:06.119475Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-12T17:59:23.414838Z","iopub.execute_input":"2025-01-12T17:59:23.415255Z","iopub.status.idle":"2025-01-12T17:59:23.420952Z","shell.execute_reply.started":"2025-01-12T17:59:23.415221Z","shell.execute_reply":"2025-01-12T17:59:23.419924Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"\ntarget_col = \"responder_6\"\n# feature_cols = [\"symbol_id\", \"time_id\"] + [f\"feature_{idx:02d}\" for idx in range(79)]+ [f\"responder_{idx}_lag_1\" for idx in range(9)]\nfeature_cols = [\"symbol_id\", \"time_id\"]+[f\"feature_{idx:02d}\" for idx in range(79)]+ [f\"responder_{idx}\" for idx in range(9)]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-12T17:59:00.906611Z","iopub.execute_input":"2025-01-12T17:59:00.907068Z","iopub.status.idle":"2025-01-12T17:59:00.911797Z","shell.execute_reply.started":"2025-01-12T17:59:00.907029Z","shell.execute_reply":"2025-01-12T17:59:00.910690Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\n\ndf = pd.read_parquet(path)\ndf=df.fillna(method='ffill').fillna(0)\n\n\n# Split the data\nx_train, x_val, y_train, y_val = train_test_split(df[feature_cols], df['responder_6'], test_size=0.2, shuffle=False)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-12T19:56:20.374559Z","iopub.execute_input":"2025-01-12T19:56:20.375111Z","iopub.status.idle":"2025-01-12T19:56:29.596899Z","shell.execute_reply.started":"2025-01-12T19:56:20.375072Z","shell.execute_reply":"2025-01-12T19:56:29.595832Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"resnset Model\n","metadata":{}},{"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow.keras import layers, models, optimizers\nfrom tensorflow.keras.applications import ResNet50\nfrom tensorflow.keras.preprocessing.image import ImageDataGenerator","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-12T19:56:29.598292Z","iopub.execute_input":"2025-01-12T19:56:29.598662Z","iopub.status.idle":"2025-01-12T19:56:29.604064Z","shell.execute_reply.started":"2025-01-12T19:56:29.598628Z","shell.execute_reply":"2025-01-12T19:56:29.602958Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow.keras import layers, models\n\ndef resnet_block_1d(input_layer, filters, kernel_size=3, strides=1):\n    x = layers.Conv1D(filters, kernel_size, strides=strides, padding=\"same\", activation=\"relu\")(input_layer)\n    x = layers.BatchNormalization()(x)\n    x = layers.Conv1D(filters, kernel_size, strides=1, padding=\"same\")(x)\n    x = layers.BatchNormalization()(x)\n    shortcut = layers.Conv1D(filters, kernel_size=1, strides=strides, padding=\"same\")(input_layer)\n    x = layers.add([x, shortcut])\n    x = layers.ReLU()(x)\n    return x\n\ndef build_resnet_variable(input_features, num_classes):\n    inputs = layers.Input(shape=(None, input_features))  \n    \n    x = layers.Conv1D(64, kernel_size=7, strides=2, padding=\"same\", activation=\"relu\")(inputs)\n    x = layers.BatchNormalization()(x)\n    x = layers.MaxPooling1D(pool_size=3, strides=2, padding=\"same\")(x)\n    x = resnet_block_1d(x, filters=64)\n    x = resnet_block_1d(x, filters=128, strides=2)\n    x = resnet_block_1d(x, filters=256, strides=2)\n    x = resnet_block_1d(x, filters=512, strides=2)\n    \n    x = layers.GlobalAveragePooling1D()(x)\n    outputs = layers.Dense(num_classes, activation=\"softmax\" if num_classes > 1 else \"linear\")(x)\n    \n    model = models.Model(inputs=inputs, outputs=outputs)\n    return model\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-12T19:56:29.605558Z","iopub.execute_input":"2025-01-12T19:56:29.605904Z","iopub.status.idle":"2025-01-12T19:56:29.620542Z","shell.execute_reply.started":"2025-01-12T19:56:29.605878Z","shell.execute_reply":"2025-01-12T19:56:29.619493Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-12T18:37:38.689196Z","iopub.execute_input":"2025-01-12T18:37:38.689568Z","iopub.status.idle":"2025-01-12T18:37:38.695622Z","shell.execute_reply.started":"2025-01-12T18:37:38.689534Z","shell.execute_reply":"2025-01-12T18:37:38.694299Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"input_shape = x_train.shape[1] # (time_steps, features), modify as needed\nnum_classes = 1  # For classification (set to 1 for regression)\n\nmodel = build_resnet_variable(input_shape, num_classes)\nmodel.compile(optimizer=\"adam\", \n              loss=\"mse\", \n              metrics=[\"mae\"])\n\nmodel.summary()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-12T19:56:29.621542Z","iopub.execute_input":"2025-01-12T19:56:29.621842Z","iopub.status.idle":"2025-01-12T19:56:29.883311Z","shell.execute_reply.started":"2025-01-12T19:56:29.621812Z","shell.execute_reply":"2025-01-12T19:56:29.882330Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_train.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-12T19:07:54.169286Z","iopub.execute_input":"2025-01-12T19:07:54.169667Z","iopub.status.idle":"2025-01-12T19:07:54.175899Z","shell.execute_reply.started":"2025-01-12T19:07:54.169637Z","shell.execute_reply":"2025-01-12T19:07:54.174789Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_train = y_train.to_numpy()\n\n# Reshape to (samples, time_steps, features) for Conv1D\n# Assuming each row is a time series with 100 time steps and 1 feature\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-12T19:08:29.433265Z","iopub.execute_input":"2025-01-12T19:08:29.433594Z","iopub.status.idle":"2025-01-12T19:08:29.438003Z","shell.execute_reply.started":"2025-01-12T19:08:29.433568Z","shell.execute_reply":"2025-01-12T19:08:29.436970Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import numpy as np\ny_train = np.array(y_train, dtype=np.float32)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-12T19:11:51.348835Z","iopub.execute_input":"2025-01-12T19:11:51.349242Z","iopub.status.idle":"2025-01-12T19:11:51.355090Z","shell.execute_reply.started":"2025-01-12T19:11:51.349206Z","shell.execute_reply":"2025-01-12T19:11:51.354040Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_train.shape\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-12T19:42:10.556557Z","iopub.execute_input":"2025-01-12T19:42:10.556901Z","iopub.status.idle":"2025-01-12T19:42:10.562999Z","shell.execute_reply.started":"2025-01-12T19:42:10.556873Z","shell.execute_reply":"2025-01-12T19:42:10.561869Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"x_train=x_train.to_numpy()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-12T19:59:01.697007Z","iopub.execute_input":"2025-01-12T19:59:01.697404Z","iopub.status.idle":"2025-01-12T19:59:03.724434Z","shell.execute_reply.started":"2025-01-12T19:59:01.697374Z","shell.execute_reply":"2025-01-12T19:59:03.723338Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"x_train.shape\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-12T20:01:07.283695Z","iopub.execute_input":"2025-01-12T20:01:07.284122Z","iopub.status.idle":"2025-01-12T20:01:07.290128Z","shell.execute_reply.started":"2025-01-12T20:01:07.284088Z","shell.execute_reply":"2025-01-12T20:01:07.288845Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"\nx_train = x_train.reshape(x_train.shape[2], x_train.shape[1],x_train.shape[0])  # Reshape to (500, 1)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-12T20:00:55.267311Z","iopub.execute_input":"2025-01-12T20:00:55.267687Z","iopub.status.idle":"2025-01-12T20:00:55.272209Z","shell.execute_reply.started":"2025-01-12T20:00:55.267661Z","shell.execute_reply":"2025-01-12T20:00:55.271101Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-12T20:01:03.444121Z","iopub.execute_input":"2025-01-12T20:01:03.444498Z","iopub.status.idle":"2025-01-12T20:01:03.451839Z","shell.execute_reply.started":"2025-01-12T20:01:03.444470Z","shell.execute_reply":"2025-01-12T20:01:03.450601Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_train.reshape(0,1,y_train[0])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-12T19:14:03.832681Z","iopub.execute_input":"2025-01-12T19:14:03.833186Z","iopub.status.idle":"2025-01-12T19:14:03.864139Z","shell.execute_reply.started":"2025-01-12T19:14:03.833136Z","shell.execute_reply":"2025-01-12T19:14:03.862561Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"x_train.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-12T19:49:24.491958Z","iopub.execute_input":"2025-01-12T19:49:24.492395Z","iopub.status.idle":"2025-01-12T19:49:24.498476Z","shell.execute_reply.started":"2025-01-12T19:49:24.492363Z","shell.execute_reply":"2025-01-12T19:49:24.497404Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"\nmodel.fit(x_train, y_train, epochs=2, batch_size=32)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-12T20:09:37.433122Z","iopub.execute_input":"2025-01-12T20:09:37.433471Z","iopub.status.idle":"2025-01-12T22:37:50.478515Z","shell.execute_reply.started":"2025-01-12T20:09:37.433445Z","shell.execute_reply":"2025-01-12T22:37:50.475832Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import joblib\n\njoblib.dump(model, 'ResNetModel.pkl')\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-12T22:38:42.111619Z","iopub.execute_input":"2025-01-12T22:38:42.112220Z","iopub.status.idle":"2025-01-12T22:38:42.468676Z","shell.execute_reply.started":"2025-01-12T22:38:42.112183Z","shell.execute_reply":"2025-01-12T22:38:42.467590Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"x_val.shape[0]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-12T22:42:50.269157Z","iopub.execute_input":"2025-01-12T22:42:50.269530Z","iopub.status.idle":"2025-01-12T22:42:50.275721Z","shell.execute_reply.started":"2025-01-12T22:42:50.269501Z","shell.execute_reply":"2025-01-12T22:42:50.274664Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"x_val = x_val.to_numpy()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-12T22:43:28.462623Z","iopub.execute_input":"2025-01-12T22:43:28.463098Z","iopub.status.idle":"2025-01-12T22:43:29.030157Z","shell.execute_reply.started":"2025-01-12T22:43:28.463058Z","shell.execute_reply":"2025-01-12T22:43:29.029075Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"x_val = x_val.reshape(x_val.shape[0],1, x_val.shape[1])\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-12T22:43:41.868480Z","iopub.execute_input":"2025-01-12T22:43:41.868804Z","iopub.status.idle":"2025-01-12T22:43:41.873407Z","shell.execute_reply.started":"2025-01-12T22:43:41.868776Z","shell.execute_reply":"2025-01-12T22:43:41.872207Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"x_val.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-12T22:43:54.897062Z","iopub.execute_input":"2025-01-12T22:43:54.897410Z","iopub.status.idle":"2025-01-12T22:43:54.903351Z","shell.execute_reply.started":"2025-01-12T22:43:54.897382Z","shell.execute_reply":"2025-01-12T22:43:54.902316Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.metrics import r2_score\n\npredictions = model.predict(x_val)\nprint(predictions)\nr2_score_test = r2_score(y_val, predictions)\nprint(f\"R2 Score on Test Partition: {r2_score_test}\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-12T22:47:08.302334Z","iopub.execute_input":"2025-01-12T22:47:08.302833Z","iopub.status.idle":"2025-01-12T22:48:36.400012Z","shell.execute_reply.started":"2025-01-12T22:47:08.302790Z","shell.execute_reply":"2025-01-12T22:48:36.398869Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"tt=predictions.reshape(-1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-12T23:12:39.543553Z","iopub.execute_input":"2025-01-12T23:12:39.543907Z","iopub.status.idle":"2025-01-12T23:12:39.548296Z","shell.execute_reply.started":"2025-01-12T23:12:39.543876Z","shell.execute_reply":"2025-01-12T23:12:39.547235Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"tt.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-12T23:12:47.623566Z","iopub.execute_input":"2025-01-12T23:12:47.623909Z","iopub.status.idle":"2025-01-12T23:12:47.630777Z","shell.execute_reply.started":"2025-01-12T23:12:47.623882Z","shell.execute_reply":"2025-01-12T23:12:47.629372Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import os\nimport polars as pl\nimport kaggle_evaluation.jane_street_inference_server","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-12T22:53:05.389871Z","iopub.execute_input":"2025-01-12T22:53:05.390303Z","iopub.status.idle":"2025-01-12T22:53:05.912124Z","shell.execute_reply.started":"2025-01-12T22:53:05.390272Z","shell.execute_reply":"2025-01-12T22:53:05.911044Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# lags_ : pl.DataFrame | None = None\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 10 minutes of the batch features being provided.\n# def 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#     predictions = test.select(\n#         'row_id',\n#         pl.lit(0.0).alias('responder_6'),\n#     )\n    \n#     feature_names = [f\"feature_{i:02d}\" for i in range(79)]\n#     feat = test[feature_names].to_numpy()\n    \n#     pred = [model.predict(feat) for model in models_1]\n#     pred = np.mean(pred, axis=0)\n#     # print(\"Pred =\", pred)\n#     # predictions = predictions.with_columns(pl.Series('responder_6', pred.ravel()))\n#     symbol_ids = test.select('symbol_id').to_numpy()[:, 0]\n\n#     if not lags is None:\n#         lags = lags.group_by([\"date_id\", \"symbol_id\"], maintain_order=True).last() # pick up last record of previous date\n#         test = test.join(lags, on=[\"date_id\", \"symbol_id\"],  how=\"left\")\n#     else:\n#         test = test.with_columns(\n#             ( pl.lit(0.0).alias(f'responder_{idx}_lag_1') for idx in range(9) )\n#         )\n    \n#     preds = np.zeros((test.shape[0],))\n#     preds += xgb_model.predict(test[xgb_feature_cols].to_pandas()) / 2\n    \n#     test_input = test[CONFIG.feature_cols].to_pandas()\n#     test_input = test_input.fillna(method = 'ffill').fillna(0)\n#     test_input = torch.FloatTensor(test_input.values).to(\"cuda:0\")\n#     with torch.no_grad():\n#         for i, nn_model in enumerate(tqdm(models)):\n#             nn_model.eval()\n#             preds += nn_model(test_input).cpu().numpy() / 10\n            \n#     # print(f\"predict> preds.shape =\", preds.shape)\n    \n#     # print(pred.shape)\n#     final_pred = (preds + pred) / 2\n#     predictions = \\\n#     test.select('row_id').\\\n#     with_columns(\n#         pl.Series(\n#             name   = 'responder_6', \n#             values = np.clip(final_pred, a_min = -5, a_max = 5),\n#             dtype  = pl.Float64,\n#         )\n#     )\n#     # print(predictions)\n#     # The predict function must return a DataFrame\n#     assert isinstance(predictions, pl.DataFrame | pd.DataFrame)\n#     # with columns 'row_id', 'responer_6'\n#     assert list(predictions.columns) == ['row_id', 'responder_6']\n#     # and as many rows as the test data.\n#     assert len(predictions) == len(test)\n\n#     return predictions","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-12T22:53:06.942348Z","iopub.execute_input":"2025-01-12T22:53:06.942809Z","iopub.status.idle":"2025-01-12T22:53:06.953492Z","shell.execute_reply.started":"2025-01-12T22:53:06.942770Z","shell.execute_reply":"2025-01-12T22:53:06.952262Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-12T23:17:51.501365Z","iopub.execute_input":"2025-01-12T23:17:51.501749Z","iopub.status.idle":"2025-01-12T23:17:52.905162Z","shell.execute_reply.started":"2025-01-12T23:17:51.501714Z","shell.execute_reply":"2025-01-12T23:17:52.903917Z"}},"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 | pd.DataFrame:\n    global lags_\n    if lags is not None:\n        lags_ = lags\n\n    predictions = test.select(\n        'row_id',\n        pl.lit(0.0).alias('responder_6'),\n    )\n    feature_names = [f\"feature_{i:02d}\" for i in range(90)]\n    feat = test[feature_names].to_numpy()\n    feat = feat.reshape(feat.shape[0], 1, feat.shape[1])\n\n    pred = model.predict(feat)\n    pred=pred.reshape(-1)\n    print(pred.shape, pred.min(), pred.max())\n    predictions = predictions.with_columns(pl.Series('responder_6', pred.ravel()))\n\n    assert isinstance(predictions, pl.DataFrame | pd.DataFrame)\n    # with columns 'row_id', 'responder_6'\n    assert list(predictions.columns) == ['row_id', 'responder_6']\n    # and as many rows as the test data.\n    assert len(predictions) == len(test)\n\n    return predictions\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-12T23:17:24.966611Z","iopub.execute_input":"2025-01-12T23:17:24.967039Z","iopub.status.idle":"2025-01-12T23:17:24.975226Z","shell.execute_reply.started":"2025-01-12T23:17:24.967006Z","shell.execute_reply":"2025-01-12T23:17:24.973954Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"inference_server = kaggle_evaluation.jane_street_inference_server.JSInferenceServer(predict)\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":"2025-01-12T23:42:27.598484Z","iopub.execute_input":"2025-01-12T23:42:27.598836Z","iopub.status.idle":"2025-01-12T23:42:27.673782Z","shell.execute_reply.started":"2025-01-12T23:42:27.598798Z","shell.execute_reply":"2025-01-12T23:42:27.672363Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"feature_names = df.columns\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-12T23:42:11.352714Z","iopub.execute_input":"2025-01-12T23:42:11.353224Z","iopub.status.idle":"2025-01-12T23:42:11.358234Z","shell.execute_reply.started":"2025-01-12T23:42:11.353176Z","shell.execute_reply":"2025-01-12T23:42:11.356892Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"feature_names","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-12T23:42:17.835266Z","iopub.execute_input":"2025-01-12T23:42:17.835626Z","iopub.status.idle":"2025-01-12T23:42:17.844376Z","shell.execute_reply.started":"2025-01-12T23:42:17.835593Z","shell.execute_reply":"2025-01-12T23:42:17.843340Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"lags_ : pl.DataFrame | None = None\nfeature_names = df.columns\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 10 minutes 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    predictions = test.select(\n        'row_id',\n        pl.lit(0.0).alias('responder_6'),\n    )\n    \n    feat = test[feature_names].to_numpy()\n    feat = feat.reshape(feat.shape[0], 1, feat.shape[1])\n    pred = model.predict(feat)\n    pred=pred.reshape(-1)\n\n    predictions = predictions.with_columns(pl.Series('responder_6', pred.ravel()))\n\n    # The predict function must return a DataFrame\n    assert isinstance(predictions, pl.DataFrame | pd.DataFrame)\n    # with columns 'row_id', 'responer_6'\n    assert list(predictions.columns) == ['row_id', 'responder_6']\n    # and as many rows as the test data.\n    assert len(predictions) == len(test)\n\n    return predictions","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-12T23:42:22.441009Z","iopub.execute_input":"2025-01-12T23:42:22.441376Z","iopub.status.idle":"2025-01-12T23:42:22.448593Z","shell.execute_reply.started":"2025-01-12T23:42:22.441347Z","shell.execute_reply":"2025-01-12T23:42:22.447532Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}