Loading

Data Science Machine Learning Challenge

Starter Notebook For Dwell Time Prediction Challenge

A getting started code for the challenge.

ashivani

What is the notebook about?

Use historical dwell time data at customer locations and create a predictive model to estimate dwell time (DWELL_TIME).

How to use this notebook? 📝

Instructions

  • The notebook follows a particular format, please stick to it.
  • Do not delete the header of the cell.
  • Use ony environment variables in AIcrowd Runtime Configuration Section.
  • During Evaluation, the notebook will be run as it is, so any error in notebook will cause errors while evaluation

Update the config parameters. You can define the common variables here

Variable Description
AICROWD_TRAIN_DATASET_PATH Path to the file containing test data.
AICROWD_TEST_DATASET_PATH Path to the file containing test data.
AICROWD_PREDICTIONS_PATH Path to write the output to.
AICROWD_API_KEY In order to submit your code to AIcrowd, you need to provide your account's API key. This key is available at https://www.aicrowd.com/participants/me

Setup AIcrowd Utilities 🛠

We use this to bundle the files for submission and create a submission on AIcrowd. Do not edit this block.

In [ ]:
!pip install -U aicrowd-cli
Collecting git+https://gitlab.aicrowd.com/aicrowd/aicrowd-cli.git@hotfix/fix-jupyter-notebook-paths
  Cloning https://gitlab.aicrowd.com/aicrowd/aicrowd-cli.git (to revision hotfix/fix-jupyter-notebook-paths) to /tmp/pip-req-build-jwhjfrut
Requirement already satisfied, skipping upgrade: click<8,>=7.1.2 in /home/ayush/anaconda3/lib/python3.8/site-packages (from aicrowd-cli==0.1.3+2.g2a2a991) (7.1.2)
Requirement already satisfied, skipping upgrade: gitpython<4,>=3.1.12 in /home/ayush/anaconda3/lib/python3.8/site-packages (from aicrowd-cli==0.1.3+2.g2a2a991) (3.1.14)
Requirement already satisfied, skipping upgrade: requests<3,>=2.25.1 in /home/ayush/anaconda3/lib/python3.8/site-packages (from aicrowd-cli==0.1.3+2.g2a2a991) (2.25.1)
Requirement already satisfied, skipping upgrade: requests-toolbelt<1,>=0.9.1 in /home/ayush/anaconda3/lib/python3.8/site-packages (from aicrowd-cli==0.1.3+2.g2a2a991) (0.9.1)
Requirement already satisfied, skipping upgrade: rich<11,>=10.0.0 in /home/ayush/anaconda3/lib/python3.8/site-packages (from aicrowd-cli==0.1.3+2.g2a2a991) (10.1.0)
Requirement already satisfied, skipping upgrade: toml<1,>=0.10.2 in /home/ayush/anaconda3/lib/python3.8/site-packages (from aicrowd-cli==0.1.3+2.g2a2a991) (0.10.2)
Requirement already satisfied, skipping upgrade: tqdm<5,>=4.56.0 in /home/ayush/anaconda3/lib/python3.8/site-packages (from aicrowd-cli==0.1.3+2.g2a2a991) (4.60.0)
Requirement already satisfied, skipping upgrade: gitdb<5,>=4.0.1 in /home/ayush/anaconda3/lib/python3.8/site-packages (from gitpython<4,>=3.1.12->aicrowd-cli==0.1.3+2.g2a2a991) (4.0.7)
Requirement already satisfied, skipping upgrade: certifi>=2017.4.17 in /home/ayush/anaconda3/lib/python3.8/site-packages (from requests<3,>=2.25.1->aicrowd-cli==0.1.3+2.g2a2a991) (2020.6.20)
Requirement already satisfied, skipping upgrade: chardet<5,>=3.0.2 in /home/ayush/anaconda3/lib/python3.8/site-packages (from requests<3,>=2.25.1->aicrowd-cli==0.1.3+2.g2a2a991) (3.0.4)
Requirement already satisfied, skipping upgrade: urllib3<1.27,>=1.21.1 in /home/ayush/anaconda3/lib/python3.8/site-packages (from requests<3,>=2.25.1->aicrowd-cli==0.1.3+2.g2a2a991) (1.25.11)
Requirement already satisfied, skipping upgrade: idna<3,>=2.5 in /home/ayush/anaconda3/lib/python3.8/site-packages (from requests<3,>=2.25.1->aicrowd-cli==0.1.3+2.g2a2a991) (2.10)
Requirement already satisfied, skipping upgrade: typing-extensions<4.0.0,>=3.7.4 in /home/ayush/anaconda3/lib/python3.8/site-packages (from rich<11,>=10.0.0->aicrowd-cli==0.1.3+2.g2a2a991) (3.7.4.3)
Requirement already satisfied, skipping upgrade: pygments<3.0.0,>=2.6.0 in /home/ayush/anaconda3/lib/python3.8/site-packages (from rich<11,>=10.0.0->aicrowd-cli==0.1.3+2.g2a2a991) (2.7.2)
Requirement already satisfied, skipping upgrade: commonmark<0.10.0,>=0.9.0 in /home/ayush/anaconda3/lib/python3.8/site-packages (from rich<11,>=10.0.0->aicrowd-cli==0.1.3+2.g2a2a991) (0.9.1)
Requirement already satisfied, skipping upgrade: colorama<0.5.0,>=0.4.0 in /home/ayush/anaconda3/lib/python3.8/site-packages (from rich<11,>=10.0.0->aicrowd-cli==0.1.3+2.g2a2a991) (0.4.4)
Requirement already satisfied, skipping upgrade: smmap<5,>=3.0.1 in /home/ayush/anaconda3/lib/python3.8/site-packages (from gitdb<5,>=4.0.1->gitpython<4,>=3.1.12->aicrowd-cli==0.1.3+2.g2a2a991) (4.0.0)
Building wheels for collected packages: aicrowd-cli
  Building wheel for aicrowd-cli (setup.py) ... done
  Created wheel for aicrowd-cli: filename=aicrowd_cli-0.1.3+2.g2a2a991-py3-none-any.whl size=46610 sha256=f5c4a5066986096edc3cf3f36564c26013f58f8e842389d189a101b1220d4b6c
  Stored in directory: /tmp/pip-ephem-wheel-cache-sx7ku3j3/wheels/93/79/18/8fc98856efd8790e948fec98f1645dce07aa41553762bf56e8
Successfully built aicrowd-cli
Installing collected packages: aicrowd-cli
  Attempting uninstall: aicrowd-cli
    Found existing installation: aicrowd-cli 0.1.3+2.gb33ebb5
    Uninstalling aicrowd-cli-0.1.3+2.gb33ebb5:
      Successfully uninstalled aicrowd-cli-0.1.3+2.gb33ebb5
Successfully installed aicrowd-cli-0.1.3+2.g2a2a991
Note: you may need to restart the kernel to use updated packages.

AIcrowd Runtime Configuration 🧷

Define configuration parameters. Please include any files needed for the notebook to run under ASSETS_DIR. We will copy the contents of this directory to your final submission file πŸ™‚

In [ ]:
import os

# Please use the absolute for the location of the dataset.
# Or you can use relative path with `os.getcwd() + "test_data/test.csv"`
AICROWD_TRAIN_DATASET_PATH = os.getenv("AICROWD_TRAIN_DATASET_PATH", "train.csv")
AICROWD_TEST_DATASET_PATH = os.getenv("AICROWD_TEST_DATASET_PATH", "test.csv")
AICROWD_PREDICTIONS_PATH = os.getenv("AICROWD_PREDICTIONS_PATH", "predictions.csv")
AICROWD_API_KEY = "" # Get your key from https://www.aicrowd.com/participants/me

Download datasets from AIcrowd

In [ ]:
!aicrowd login --api-key $AICROWD_API_KEY
!aicrowd dataset download --challenge xpo-logistics-data-science-machine-learning-challenge
Error: --api-key option requires an argument
train.csv:   0%|                                     | 0.00/808k [00:00<?, ?B/s]
train.csv: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 808k/808k [00:01<00:00, 699kB/s]

test.csv: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 237k/237k [00:00<00:00, 278kB/s]

Install packages 🗃

Please add all pacakage installations in this section

In [ ]:
!pip install numpy pandas sklearn

Define preprocessing code 💻

The code that is common between the training and the prediction sections should be defined here. During evaluation, we completely skip the training section. Please make sure to add any common logic between the training and prediction sections here.

Import common packages

Please import packages that are common for training and prediction phases here.

In [ ]:
import numpy as np
import pandas as pd
In [ ]:
# some precessing code

Training phase ⚙️

You can define your training code here. This sections will be skipped during evaluation.

In [ ]:
# model = define_your_model

Load training data

In [ ]:
# load your data

Train your model

In [ ]:
# model.fit(train_data)
In [ ]:
# some custom code block

Prediction phase 🔎

Please make sure to save the weights from the training section in your assets directory and load them in this section

In [ ]:
# some custom code

Load test data

In [ ]:
test_data = pd.read_csv(AICROWD_TEST_DATASET_PATH)
test_data.head()

Generate predictions

In [ ]:
predictions = {
    "DWELL_TIME": np.random.rand(len(test_data["DL"]))
}

predictions_df = pd.DataFrame.from_dict(predictions)

Save predictions 📨

In [ ]:
predictions_df.to_csv(AICROWD_PREDICTIONS_PATH, index=False)

Submit to AIcrowd 🚀

NOTE: PLEASE SAVE THE NOTEBOOK BEFORE SUBMITTING IT (Ctrl + S)

In [ ]:
!aicrowd login --api-key $AICROWD_API_KEY
!aicrowd notebook submit --dry-run \
    --assets-dir "assets" \
    --no-verify \
    --challenge data-science-machine-learning-challenge
Error: --api-key option requires an argument
Using notebook: /home/ayush/ayush/ayush/Intern/AIcrowd/challenges/xpo_dwell/starter_kit_aicrowd_python_submission_v2.ipynb for submission...
Removing existing files from submission directory...
Scrubbing API keys from the notebook...
Collecting notebook...
In [ ]:

In [ ]:


Comments

You must login before you can post a comment.

Execute