{"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":30786,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Mainly for model training\n\nDepending on the size of your training set, you will need an [inference notebook](https://www.kaggle.com/code/regisvargas/inference-jane-street-a-beginner-s-notebook).","metadata":{}},{"cell_type":"code","source":"import pandas as pd\nimport gc\n# Initialize a list to hold samples from each file\nsamples = []\n# Load a sample from each file\n#for i in range(10):\nfor i in [9]:\n    file_path = f\"/kaggle/input/jane-street-real-time-market-data-forecasting/train.parquet/partition_id={i}/part-0.parquet\"\n    chunk = pd.read_parquet(file_path)\n    \n    # Take a sample of the data (adjust sample size as needed)\n    sample_chunk = chunk.sample(n=5000, random_state=42)  # For example, 100 rows\n    #sample_chunk = chunk\n    samples.append(sample_chunk)\n# Concatenate all samples into one DataFrame if needed\ndel chunk\ngc.collect()  # Forces garbage collection\nsample_df = pd.concat(samples, ignore_index=True)\ndel samples\ngc.collect()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-22T06:55:57.038173Z","iopub.execute_input":"2024-11-22T06:55:57.038565Z","iopub.status.idle":"2024-11-22T06:56:04.250400Z","shell.execute_reply.started":"2024-11-22T06:55:57.038530Z","shell.execute_reply":"2024-11-22T06:56:04.249172Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sample_df","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-22T06:56:10.738458Z","iopub.execute_input":"2024-11-22T06:56:10.738865Z","iopub.status.idle":"2024-11-22T06:56:10.766370Z","shell.execute_reply.started":"2024-11-22T06:56:10.738828Z","shell.execute_reply":"2024-11-22T06:56:10.765291Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sample_df.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-22T06:58:57.711213Z","iopub.execute_input":"2024-11-22T06:58:57.713025Z","iopub.status.idle":"2024-11-22T06:58:57.738326Z","shell.execute_reply.started":"2024-11-22T06:58:57.712959Z","shell.execute_reply":"2024-11-22T06:58:57.737193Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Prepare data","metadata":{}},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport tensorflow as tf\nfrom tensorflow.keras import layers, models\n# Separate features and responders\nfeatures = sample_df.filter(regex='^feature_')\nresponders = sample_df.filter(regex='^responder_')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-22T06:59:23.870187Z","iopub.execute_input":"2024-11-22T06:59:23.871086Z","iopub.status.idle":"2024-11-22T06:59:36.534029Z","shell.execute_reply.started":"2024-11-22T06:59:23.871025Z","shell.execute_reply":"2024-11-22T06:59:36.532997Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"features.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-22T06:59:46.312660Z","iopub.execute_input":"2024-11-22T06:59:46.313185Z","iopub.status.idle":"2024-11-22T06:59:46.337650Z","shell.execute_reply.started":"2024-11-22T06:59:46.313131Z","shell.execute_reply":"2024-11-22T06:59:46.336648Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"responders.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-22T07:00:10.410315Z","iopub.execute_input":"2024-11-22T07:00:10.410710Z","iopub.status.idle":"2024-11-22T07:00:10.426239Z","shell.execute_reply.started":"2024-11-22T07:00:10.410674Z","shell.execute_reply":"2024-11-22T07:00:10.424780Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"weights = sample_df['weight']\nweights.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-22T07:00:27.312976Z","iopub.execute_input":"2024-11-22T07:00:27.313486Z","iopub.status.idle":"2024-11-22T07:00:27.322410Z","shell.execute_reply.started":"2024-11-22T07:00:27.313438Z","shell.execute_reply":"2024-11-22T07:00:27.321165Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X = features.values  # Features for input\nX","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-22T07:01:01.928893Z","iopub.execute_input":"2024-11-22T07:01:01.929893Z","iopub.status.idle":"2024-11-22T07:01:01.939388Z","shell.execute_reply.started":"2024-11-22T07:01:01.929835Z","shell.execute_reply":"2024-11-22T07:01:01.938461Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport tensorflow as tf\nfrom tensorflow.keras import layers, models\n# Separate features and responders\nfeatures = sample_df.filter(regex='^feature_')\nresponders = sample_df.filter(regex='^responder_')\nweights = sample_df['weight']\n# Convert to numpy arrays for TensorFlow\nX = features.values  # Features for input\n#y = responders.values  # Responders for output\n# Assuming you have a DataFrame `y_train` with all responders\ny = responders[['responder_6']].values  # Keep only responder_6\nX = np.nan_to_num(X, nan=0.0, posinf=0.0, neginf=0.0)\ny = np.nan_to_num(y, nan=0.0, posinf=0.0, neginf=0.0)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-22T07:02:16.187319Z","iopub.execute_input":"2024-11-22T07:02:16.187780Z","iopub.status.idle":"2024-11-22T07:02:16.205805Z","shell.execute_reply.started":"2024-11-22T07:02:16.187740Z","shell.execute_reply":"2024-11-22T07:02:16.204765Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"Is_keras = False","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-22T07:02:23.596750Z","iopub.execute_input":"2024-11-22T07:02:23.597138Z","iopub.status.idle":"2024-11-22T07:02:23.601609Z","shell.execute_reply.started":"2024-11-22T07:02:23.597100Z","shell.execute_reply":"2024-11-22T07:02:23.600502Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import pandas as pd\nfrom sklearn.model_selection import train_test_split\nX_train, X_val, y_train, y_val, weights_train, weights_val = train_test_split(\n    X, y, weights, test_size=0.2, random_state=42\n)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-22T07:05:12.981745Z","iopub.execute_input":"2024-11-22T07:05:12.982195Z","iopub.status.idle":"2024-11-22T07:05:12.990502Z","shell.execute_reply.started":"2024-11-22T07:05:12.982155Z","shell.execute_reply":"2024-11-22T07:05:12.989511Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Training Autoencoder for compact representation","metadata":{}},{"cell_type":"code","source":"rows = X_train.shape[0] \ndim = X_train.shape[1] \nprint(rows)\nprint(dim)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-22T07:06:34.997154Z","iopub.execute_input":"2024-11-22T07:06:34.997953Z","iopub.status.idle":"2024-11-22T07:06:35.003941Z","shell.execute_reply.started":"2024-11-22T07:06:34.997909Z","shell.execute_reply":"2024-11-22T07:06:35.002679Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from tensorflow.keras import layers, models\nfrom tensorflow.keras.callbacks import EarlyStopping, ReduceLROnPlateau\n# Define the Autoencoder model\ninput_dim = X_train.shape[1]  # Number of features\nlatent_dim = 32  # Dimension of the bottleneck layer\nencoder_input = layers.Input(shape=(input_dim,))\nx = layers.Dense(128, activation='relu')(encoder_input)\nx = layers.Dense(64, activation='relu')(x)\nbottleneck = layers.Dense(latent_dim, activation='linear', name='bottleneck')(x)  # Encoder output\n# Decoder\nx = layers.Dense(64, activation='relu')(bottleneck)\nx = layers.Dense(128, activation='relu')(x)\ndecoder_output = layers.Dense(input_dim, activation='linear')(x)\nautoencoder = models.Model(encoder_input, decoder_output, name=\"Autoencoder\")\n# Compile the Autoencoder\nautoencoder.compile(optimizer=\"adam\", loss=\"mse\")\nautoencoder.summary()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-22T07:08:45.440193Z","iopub.execute_input":"2024-11-22T07:08:45.440626Z","iopub.status.idle":"2024-11-22T07:08:45.571467Z","shell.execute_reply.started":"2024-11-22T07:08:45.440591Z","shell.execute_reply":"2024-11-22T07:08:45.570587Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"\n# Define callbacks\nearly_stopping = EarlyStopping(monitor=\"val_loss\", patience=10, restore_best_weights=True, min_delta = 0.00001)\nreduce_lr = ReduceLROnPlateau(monitor=\"val_loss\", factor=0.5, patience=3, min_lr=1e-6)\n# Train the Autoencoder\nhistory = autoencoder.fit(\n    X_train, X_train,\n    validation_data=(X_val, X_val),\n    epochs=50,\n    batch_size=32,\n    callbacks=[early_stopping, reduce_lr]\n)\n# Extract the encoder\nencoder = models.Model(encoder_input, bottleneck, name=\"Encoder\")\nencoder.save(\"/kaggle/working/pretrained_encoder.keras\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-22T07:10:02.691372Z","iopub.execute_input":"2024-11-22T07:10:02.692540Z","iopub.status.idle":"2024-11-22T07:10:18.171562Z","shell.execute_reply.started":"2024-11-22T07:10:02.692481Z","shell.execute_reply":"2024-11-22T07:10:18.170601Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# XGBoost\n\nSee [Feature engineering, xgboost](https://www.kaggle.com/code/dlarionov/feature-engineering-xgboost#Part-2,-xgboost) and [🥇🥇Jane Street Baseline lgb, xgb and catboost🥇🥇](https://www.kaggle.com/code/yuanzhezhou/jane-street-baseline-lgb-xgb-and-catboost)for details.","metadata":{}},{"cell_type":"code","source":"# Define a learning rate schedule\ndef learning_rate_scheduler_xgb(epoch):\n    initial_rate = 0.3\n    decay_rate = 0.999\n    return initial_rate * (decay_rate ** (np.log(epoch)))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-22T07:13:03.907030Z","iopub.execute_input":"2024-11-22T07:13:03.908065Z","iopub.status.idle":"2024-11-22T07:13:03.913057Z","shell.execute_reply.started":"2024-11-22T07:13:03.908021Z","shell.execute_reply":"2024-11-22T07:13:03.911954Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from xgboost import XGBRegressor\n# Create an XGBoost model\nmodel_xgb = XGBRegressor(\n    n_estimators=2000,\n    learning_rate=learning_rate_scheduler_xgb,\n    tree_method='hist',\n    max_depth=6,\n    random_state=42\n)\n# Fit the model with sample weights and validation dataset\nmodel_xgb.fit(\n    encoder.predict(X_train),\n    y_train,\n #   sample_weight=weights_train,\n    eval_set=[(encoder.predict(X_val), y_val)],\n#    sample_weight_eval_set=[weights_train, weights_val],\n    eval_metric='rmse',\n    early_stopping_rounds=10,\n    verbose=True\n)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-22T07:13:08.126033Z","iopub.execute_input":"2024-11-22T07:13:08.126815Z","iopub.status.idle":"2024-11-22T07:13:08.879910Z","shell.execute_reply.started":"2024-11-22T07:13:08.126775Z","shell.execute_reply":"2024-11-22T07:13:08.878868Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_pred = model_xgb.predict(encoder.predict(X_val))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-22T07:13:16.409365Z","iopub.execute_input":"2024-11-22T07:13:16.410375Z","iopub.status.idle":"2024-11-22T07:13:16.523463Z","shell.execute_reply.started":"2024-11-22T07:13:16.410325Z","shell.execute_reply":"2024-11-22T07:13:16.522592Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.metrics import mean_squared_error, r2_score\nmse = mean_squared_error(y_val, y_pred, squared=False)\nr2 = r2_score(y_val, y_pred)\nprint(f\"RMSE: {mse}\")\nprint(f\"R²: {r2}\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-22T07:13:20.778001Z","iopub.execute_input":"2024-11-22T07:13:20.779013Z","iopub.status.idle":"2024-11-22T07:13:20.786737Z","shell.execute_reply.started":"2024-11-22T07:13:20.778968Z","shell.execute_reply":"2024-11-22T07:13:20.785565Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import joblib\n# Save the model\njoblib.dump(model_xgb, \"xgboost_sklearn.pkl\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-22T07:13:24.167072Z","iopub.execute_input":"2024-11-22T07:13:24.167475Z","iopub.status.idle":"2024-11-22T07:13:24.176933Z","shell.execute_reply.started":"2024-11-22T07:13:24.167440Z","shell.execute_reply":"2024-11-22T07:13:24.174921Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Build the Autoencoder Model","metadata":{}},{"cell_type":"markdown","source":"Gradient Centralization for Better Training Performance\n\nSee https://keras.io/examples/vision/gradient_centralization/ for details. ","metadata":{}},{"cell_type":"code","source":"from keras.optimizers import RMSprop\nclass GCRMSprop(RMSprop):\n    def get_gradients(self, loss, params):\n        # We here just provide a modified get_gradients() function since we are\n        # trying to just compute the centralized gradients.\n        grads = []\n        gradients = super().get_gradients()\n        for grad in gradients:\n            grad_len = len(grad.shape)\n            if grad_len > 1:\n                axis = list(range(grad_len - 1))\n                grad -= ops.mean(grad, axis=axis, keep_dims=True)\n            grads.append(grad)\n        return grads\noptimizer = GCRMSprop(learning_rate=1e-4)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-22T07:13:35.483358Z","iopub.execute_input":"2024-11-22T07:13:35.483732Z","iopub.status.idle":"2024-11-22T07:13:35.497373Z","shell.execute_reply.started":"2024-11-22T07:13:35.483701Z","shell.execute_reply":"2024-11-22T07:13:35.496350Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from tensorflow.keras.regularizers import l2\n# Define the number of input and output nodes\ninput_dim = X.shape[1]  # Number of features (79)\noutput_dim = y.shape[1]  # Number of responders (9)\n# Define the model\nmodel = models.Sequential([\n    layers.Input(shape=(input_dim,)), # Input layer\n   # layers.LayerNormalization(),\n   # layers.BatchNormalization(),\n  #  layers.Dense(128, activation='relu'),\n  #  layers.Dropout(0.2),\n    layers.Dense(64, activation='relu'),  # Encoder\n    layers.Dense(32, activation='relu'),  # Bottleneck layer (compression)\n    layers.Dense(64, activation='relu'),  # Decoder\n#    layers.Dense(128, activation='relu'), \n #   layers.Dropout(0.2),\n    layers.Dense(output_dim, activation='linear'#, kernel_regularizer=l2(0.001)\n                )  # Output layer for responders\n])\nmodel.compile(optimizer=\"adam\", loss='mse')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-22T07:13:41.227369Z","iopub.execute_input":"2024-11-22T07:13:41.228457Z","iopub.status.idle":"2024-11-22T07:13:41.275007Z","shell.execute_reply.started":"2024-11-22T07:13:41.228409Z","shell.execute_reply":"2024-11-22T07:13:41.273637Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Train Autoencoder Model","metadata":{}},{"cell_type":"code","source":"from tensorflow.keras.callbacks import LearningRateScheduler\ndef step_decay(epoch):\n    initial_lr = 0.01\n    drop = 0.5\n    epochs_drop = 5\n    lr = initial_lr * (drop ** (epoch // epochs_drop))\n    return lr\nlr_scheduler = LearningRateScheduler(step_decay)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-22T07:13:45.322054Z","iopub.execute_input":"2024-11-22T07:13:45.322854Z","iopub.status.idle":"2024-11-22T07:13:45.328311Z","shell.execute_reply.started":"2024-11-22T07:13:45.322812Z","shell.execute_reply":"2024-11-22T07:13:45.326911Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from tensorflow.keras.callbacks import ReduceLROnPlateau\nreduce_lr = ReduceLROnPlateau(monitor='val_loss', factor=0.5, patience=2, min_lr=1e-6)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-22T07:13:47.310998Z","iopub.execute_input":"2024-11-22T07:13:47.311423Z","iopub.status.idle":"2024-11-22T07:13:47.316671Z","shell.execute_reply.started":"2024-11-22T07:13:47.311383Z","shell.execute_reply":"2024-11-22T07:13:47.315436Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from tensorflow.keras.callbacks import EarlyStopping\n# Define EarlyStopping\nearly_stopping = EarlyStopping(\n    monitor='val_loss',    # Monitor validation loss\n    patience=10,            # Number of epochs to wait for improvement\n    min_delta=0.00001,       # Minimum change to qualify as an improvement\n    restore_best_weights=True  # Restore weights from the best epoch\n)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-22T07:13:48.861093Z","iopub.execute_input":"2024-11-22T07:13:48.861506Z","iopub.status.idle":"2024-11-22T07:13:48.867049Z","shell.execute_reply.started":"2024-11-22T07:13:48.861471Z","shell.execute_reply":"2024-11-22T07:13:48.865807Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"if Is_keras:\n    history = model.fit(\n    X_train, y_train,\n    sample_weight=weights_train,  # Training sample weights\n    epochs=50,\n    batch_size=32,\n    validation_data=(X_val, y_val, weights_val),  # Validation data with sample weights\n    callbacks=[early_stopping, reduce_lr]\n)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-22T07:13:50.874103Z","iopub.execute_input":"2024-11-22T07:13:50.875024Z","iopub.status.idle":"2024-11-22T07:13:50.879748Z","shell.execute_reply.started":"2024-11-22T07:13:50.874975Z","shell.execute_reply":"2024-11-22T07:13:50.878782Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"if Is_keras:\n    model.save(\"/kaggle/working/model.keras\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-22T07:13:53.813673Z","iopub.execute_input":"2024-11-22T07:13:53.815041Z","iopub.status.idle":"2024-11-22T07:13:53.821321Z","shell.execute_reply.started":"2024-11-22T07:13:53.814985Z","shell.execute_reply":"2024-11-22T07:13:53.819931Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Submission\n\nSee [Jane Street RMF Demo Submission](https://www.kaggle.com/code/ryanholbrook/jane-street-rmf-demo-submission) for details.\n\nDepending on the size of your training set, you will need an [inference notebook](https://www.kaggle.com/code/regisvargas/inference-jane-street-a-beginner-s-notebook).","metadata":{}},{"cell_type":"code","source":"import os\nimport polars as pl\nimport kaggle_evaluation.jane_street_inference_server","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-22T07:13:55.853897Z","iopub.execute_input":"2024-11-22T07:13:55.854319Z","iopub.status.idle":"2024-11-22T07:13:56.331998Z","shell.execute_reply.started":"2024-11-22T07:13:55.854280Z","shell.execute_reply":"2024-11-22T07:13:56.331122Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import polars as pl\nimport numpy as np\n# Assuming `model` is your trained model\n# Assuming features required by the model are named 'feature_00', 'feature_01', etc.\ndef predict(test: pl.DataFrame, lags: pl.DataFrame | None) -> pl.DataFrame | pd.DataFrame:\n    \"\"\"Make a prediction.\"\"\"\n    global lags_\n    if lags is not None:\n        lags_ = lags\n    # Extract the features for the model input\n    feature_columns = [col for col in test.columns if col.startswith(\"feature_\")]\n    features = test.select(feature_columns).to_numpy()  # Convert to numpy array for model input\n    features = np.nan_to_num(features, nan=0.0, posinf=0.0, neginf=0.0)\n    # Generate predictions using the model\n    #model_predictions = model.predict(features)\n    if Is_keras:\n        responder_6_predictions = model.predict(features)[:,0]\n    else:\n        responder_6_predictions = model_xgb.predict(encoder.predict(features))\n   # print(responder_6_predictions)    \n    #responder_6_predictions = model_predictions[:, 6]  # Assuming responder_6 is at index 6\n    # Create a new Polars DataFrame with row_id and responder_6 predictions\n    predictions = test.select(\"row_id\").with_columns(\n        pl.Series(\"responder_6\", responder_6_predictions)\n    )\n    print(predictions)\n    # Ensure the output format and length requirements\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    \n    assert len(predictions) == len(test)\n    return predictions","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-22T07:14:00.092340Z","iopub.execute_input":"2024-11-22T07:14:00.093105Z","iopub.status.idle":"2024-11-22T07:14:00.102128Z","shell.execute_reply.started":"2024-11-22T07:14:00.093051Z","shell.execute_reply":"2024-11-22T07:14:00.101044Z"}},"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":"2024-11-22T07:14:16.602499Z","iopub.execute_input":"2024-11-22T07:14:16.602908Z","iopub.status.idle":"2024-11-22T07:14:17.029264Z","shell.execute_reply.started":"2024-11-22T07:14:16.602868Z","shell.execute_reply":"2024-11-22T07:14:17.028027Z"}},"outputs":[],"execution_count":null}]}