Loading

ACTVT

[Getting Started Notebook] ACTVT Challange

This is a Baseline Code to get you started with the challenge.

gauransh_k

You can use this code to start understanding the data and create a baseline model for further imporvments.

Starter Code for ACTVT Practice Challange

Note : Create a copy of the notebook and use the copy for submission. Go to File > Save a Copy in Drive to create a new copy

Downloading Dataset

Installing aicrowd-cli

In [2]:
!pip install aicrowd-cli
%load_ext aicrowd.magic
Requirement already satisfied: aicrowd-cli in /home/gauransh/anaconda3/lib/python3.8/site-packages (0.1.10)
Requirement already satisfied: requests-toolbelt<1,>=0.9.1 in /home/gauransh/anaconda3/lib/python3.8/site-packages (from aicrowd-cli) (0.9.1)
Requirement already satisfied: rich<11,>=10.0.0 in /home/gauransh/anaconda3/lib/python3.8/site-packages (from aicrowd-cli) (10.15.2)
Requirement already satisfied: GitPython==3.1.18 in /home/gauransh/anaconda3/lib/python3.8/site-packages (from aicrowd-cli) (3.1.18)
Requirement already satisfied: tqdm<5,>=4.56.0 in /home/gauransh/anaconda3/lib/python3.8/site-packages (from aicrowd-cli) (4.62.2)
Requirement already satisfied: click<8,>=7.1.2 in /home/gauransh/anaconda3/lib/python3.8/site-packages (from aicrowd-cli) (7.1.2)
Requirement already satisfied: requests<3,>=2.25.1 in /home/gauransh/anaconda3/lib/python3.8/site-packages (from aicrowd-cli) (2.26.0)
Requirement already satisfied: pyzmq==22.1.0 in /home/gauransh/anaconda3/lib/python3.8/site-packages (from aicrowd-cli) (22.1.0)
Requirement already satisfied: toml<1,>=0.10.2 in /home/gauransh/anaconda3/lib/python3.8/site-packages (from aicrowd-cli) (0.10.2)
Requirement already satisfied: gitdb<5,>=4.0.1 in /home/gauransh/anaconda3/lib/python3.8/site-packages (from GitPython==3.1.18->aicrowd-cli) (4.0.9)
Requirement already satisfied: smmap<6,>=3.0.1 in /home/gauransh/anaconda3/lib/python3.8/site-packages (from gitdb<5,>=4.0.1->GitPython==3.1.18->aicrowd-cli) (5.0.0)
Requirement already satisfied: charset-normalizer~=2.0.0 in /home/gauransh/anaconda3/lib/python3.8/site-packages (from requests<3,>=2.25.1->aicrowd-cli) (2.0.0)
Requirement already satisfied: idna<4,>=2.5 in /home/gauransh/anaconda3/lib/python3.8/site-packages (from requests<3,>=2.25.1->aicrowd-cli) (3.1)
Requirement already satisfied: certifi>=2017.4.17 in /home/gauransh/anaconda3/lib/python3.8/site-packages (from requests<3,>=2.25.1->aicrowd-cli) (2021.5.30)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /home/gauransh/anaconda3/lib/python3.8/site-packages (from requests<3,>=2.25.1->aicrowd-cli) (1.26.6)
Requirement already satisfied: pygments<3.0.0,>=2.6.0 in /home/gauransh/anaconda3/lib/python3.8/site-packages (from rich<11,>=10.0.0->aicrowd-cli) (2.10.0)
Requirement already satisfied: commonmark<0.10.0,>=0.9.0 in /home/gauransh/anaconda3/lib/python3.8/site-packages (from rich<11,>=10.0.0->aicrowd-cli) (0.9.1)
Requirement already satisfied: colorama<0.5.0,>=0.4.0 in /home/gauransh/anaconda3/lib/python3.8/site-packages (from rich<11,>=10.0.0->aicrowd-cli) (0.4.4)
In [2]:
%aicrowd login
Please login here: https://api.aicrowd.com/auth/tK8jq9FaBgEDD9GACzX7OUfbHwY5nggWZgRT9hIvBqI
Opening in existing browser session.
API Key valid
Saved API Key successfully!
In [3]:
!rm -rf data
!mkdir data
%aicrowd ds dl -c actvt -o data

Importing Libraries

In this baseline, we will be using skleanr library to train the model and generate the predictions

In [18]:
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier
import os
import matplotlib.pyplot as plt
import seaborn as sns
from IPython.display import display

Reading the dataset

Here, we will read the train.csv which contains both training samples & labels, and test.csv which contains testing samples.

In [5]:
# Reading the CSV
train_data_df = pd.read_csv("data/train.csv", header=None, encoding='ISO-8859–1')
test_data_df = pd.read_csv("data/test.csv", header=None, encoding='ISO-8859–1')

# train_data.shape, test_data.shape
display(train_data_df.head())
display(test_data_df.head())
0 1 2 3 4 5 6 7
0 E04 0 633790134988473938 27.05.2009 11:31:38:847 1.758363 1.258137 -0.069686 0
1 D04 3 633790166764388169 27.05.2009 12:24:36:440 2.369551 1.552402 0.253551 0
2 C05 2 633790291840474479 27.05.2009 15:53:04:047 1.889798 1.857141 1.262779 0
3 E02 3 633790126538901749 27.05.2009 11:17:33:890 3.374718 2.152805 0.032353 6
4 E05 0 633790143697167346 27.05.2009 11:46:09:717 4.146194 1.832564 0.532300 5
0 1 2 3 4 5 6
0 C04 1 633790287766171781 27.05.2009 15:46:16:617 3.493309 1.856460 0.767770
1 B01 1 633790200344586040 27.05.2009 13:20:34:460 2.902755 1.488864 1.149231
2 D05 0 633790170148125847 27.05.2009 12:30:14:813 1.492071 1.509197 -0.200977
3 A05 2 633790242490463519 27.05.2009 14:30:49:047 1.516326 2.219613 0.426535
4 E03 3 633790130684865255 27.05.2009 11:24:28:487 2.356283 2.115891 0.303658

Data Preprocessing

In [6]:
# Separating data from the dataframe for final training
X = train_data_df.loc[:,[1,4,5,6]].to_numpy()
y = train_data_df[7].to_numpy()
print(X.shape, y.shape)
(131888, 4) (131888,)
In [7]:
# Visualising the final lable classes for training
sns.countplot(y)
/home/gauransh/anaconda3/lib/python3.8/site-packages/seaborn/_decorators.py:36: FutureWarning: Pass the following variable as a keyword arg: x. From version 0.12, the only valid positional argument will be `data`, and passing other arguments without an explicit keyword will result in an error or misinterpretation.
  warnings.warn(
Out[7]:
<AxesSubplot:ylabel='count'>

Splitting the data

In [8]:
# Splitting the training set, and training & validation
X_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.2)
print(X_train.shape)
print(y_train.shape)
(105510, 4)
(105510,)
In [9]:
X_train[0], y_train[0]
Out[9]:
(array([2.        , 2.86072111, 1.83606327, 0.50325197]), 0)

Training the Model

In [19]:
model = KNeighborsClassifier()
model.fit(X_train, y_train)
Out[19]:
KNeighborsClassifier()

Validation

In [20]:
model.score(X_val, y_val)
Out[20]:
0.6867844415801047

So, we are done with the baseline let's test with real testing data and see how we submit it to challange.

Predictions

In [21]:
# Separating data from the dataframe for final testing
X_test = test_data_df.loc[:,[1,4,5,6]].to_numpy()
print(X_test.shape)
(32972, 4)
In [22]:
# Predicting the labels
predictions = model.predict(X_test)
predictions.shape
Out[22]:
(32972,)
In [24]:
# Converting the predictions array into pandas dataset
submission = pd.DataFrame({"activity":predictions})
submission
Out[24]:
activity
0 10
1 0
2 0
3 3
4 6
... ...
32967 3
32968 5
32969 3
32970 3
32971 6

32972 rows × 1 columns

In [25]:
# Saving the pandas dataframe
!rm -rf assets
!mkdir assets
submission.to_csv(os.path.join("assets", "submission.csv"), index=False)

Submitting our Predictions

Note : Please save the notebook before submitting it (Ctrl + S)

In [26]:
!!aicrowd submission create -c actvt -f assets/submission.csv
Out[26]:
['submission.csv ━━━━━━━━━━━━━━━━━━━━━ 100.0% • 67.9/66.2 KB • 23.0 MB/s • 0:00:00',
 '                                  ╭─────────────────────────╮                                  ',
 '                                  │ Successfully submitted! │                                  ',
 '                                  ╰─────────────────────────╯                                  ',
 '                                        Important links                                        ',
 '┌──────────────────┬──────────────────────────────────────────────────────────────────────────┐',
 '│  This submission │ https://www.aicrowd.com/challenges/actvt/submissions/167546              │',
 '│                  │                                                                          │',
 '│  All submissions │ https://www.aicrowd.com/challenges/actvt/submissions?my_submissions=true │',
 '│                  │                                                                          │',
 '│      Leaderboard │ https://www.aicrowd.com/challenges/actvt/leaderboards                    │',
 '│                  │                                                                          │',
 '│ Discussion forum │ https://discourse.aicrowd.com/c/actvt                                    │',
 '│                  │                                                                          │',
 '│   Challenge page │ https://www.aicrowd.com/challenges/actvt                                 │',
 '└──────────────────┴──────────────────────────────────────────────────────────────────────────┘',
 "{'submission_id': 167546, 'created_at': '2021-12-11T16:08:44.899Z'}"]
In [ ]:


Comments

You must login before you can post a comment.

Execute