Loading

Age Prediction

[ Getting Started Notebook ] Age Prediction

A getting started notebook for the challenge.

ashivani

Age_Desktop Banner-3.png

Getting Started with Age Prediction

In this puzzle, we have to predict the age from the given human faces.

This is a starter kit explaining how to download the data and also submit direcly via this notebook.

We will be the sample submission file directly in the required format.

Download the files 💾¶

Download AIcrowd CLI

We will first install aicrowd-cli which will help you download and later make submission directly via the notebook.

In [ ]:
!pip install aicrowd-cli
%load_ext aicrowd.magic
Collecting aicrowd-cli
  Downloading aicrowd_cli-0.1.10-py3-none-any.whl (44 kB)
     |████████████████████████████████| 44 kB 1.2 MB/s 
Collecting rich<11,>=10.0.0
  Downloading rich-10.16.2-py3-none-any.whl (214 kB)
     |████████████████████████████████| 214 kB 9.3 MB/s 
Requirement already satisfied: toml<1,>=0.10.2 in /usr/local/lib/python3.7/dist-packages (from aicrowd-cli) (0.10.2)
Collecting pyzmq==22.1.0
  Downloading pyzmq-22.1.0-cp37-cp37m-manylinux1_x86_64.whl (1.1 MB)
     |████████████████████████████████| 1.1 MB 47.9 MB/s 
Collecting requests-toolbelt<1,>=0.9.1
  Downloading requests_toolbelt-0.9.1-py2.py3-none-any.whl (54 kB)
     |████████████████████████████████| 54 kB 2.0 MB/s 
Collecting requests<3,>=2.25.1
  Downloading requests-2.27.1-py2.py3-none-any.whl (63 kB)
     |████████████████████████████████| 63 kB 1.4 MB/s 
Collecting GitPython==3.1.18
  Downloading GitPython-3.1.18-py3-none-any.whl (170 kB)
     |████████████████████████████████| 170 kB 45.7 MB/s 
Requirement already satisfied: click<8,>=7.1.2 in /usr/local/lib/python3.7/dist-packages (from aicrowd-cli) (7.1.2)
Requirement already satisfied: tqdm<5,>=4.56.0 in /usr/local/lib/python3.7/dist-packages (from aicrowd-cli) (4.62.3)
Collecting gitdb<5,>=4.0.1
  Downloading gitdb-4.0.9-py3-none-any.whl (63 kB)
     |████████████████████████████████| 63 kB 1.4 MB/s 
Requirement already satisfied: typing-extensions>=3.7.4.0 in /usr/local/lib/python3.7/dist-packages (from GitPython==3.1.18->aicrowd-cli) (3.10.0.2)
Collecting smmap<6,>=3.0.1
  Downloading smmap-5.0.0-py3-none-any.whl (24 kB)
Requirement already satisfied: charset-normalizer~=2.0.0 in /usr/local/lib/python3.7/dist-packages (from requests<3,>=2.25.1->aicrowd-cli) (2.0.11)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.7/dist-packages (from requests<3,>=2.25.1->aicrowd-cli) (1.24.3)
Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.7/dist-packages (from requests<3,>=2.25.1->aicrowd-cli) (2.10)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/dist-packages (from requests<3,>=2.25.1->aicrowd-cli) (2021.10.8)
Collecting colorama<0.5.0,>=0.4.0
  Downloading colorama-0.4.4-py2.py3-none-any.whl (16 kB)
Requirement already satisfied: pygments<3.0.0,>=2.6.0 in /usr/local/lib/python3.7/dist-packages (from rich<11,>=10.0.0->aicrowd-cli) (2.6.1)
Collecting commonmark<0.10.0,>=0.9.0
  Downloading commonmark-0.9.1-py2.py3-none-any.whl (51 kB)
     |████████████████████████████████| 51 kB 5.4 MB/s 
Installing collected packages: smmap, requests, gitdb, commonmark, colorama, rich, requests-toolbelt, pyzmq, GitPython, aicrowd-cli
  Attempting uninstall: requests
    Found existing installation: requests 2.23.0
    Uninstalling requests-2.23.0:
      Successfully uninstalled requests-2.23.0
  Attempting uninstall: pyzmq
    Found existing installation: pyzmq 22.3.0
    Uninstalling pyzmq-22.3.0:
      Successfully uninstalled pyzmq-22.3.0
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
google-colab 1.0.0 requires requests~=2.23.0, but you have requests 2.27.1 which is incompatible.
datascience 0.10.6 requires folium==0.2.1, but you have folium 0.8.3 which is incompatible.
Successfully installed GitPython-3.1.18 aicrowd-cli-0.1.10 colorama-0.4.4 commonmark-0.9.1 gitdb-4.0.9 pyzmq-22.1.0 requests-2.27.1 requests-toolbelt-0.9.1 rich-10.16.2 smmap-5.0.0

Login to AIcrowd ㊗¶

In [ ]:
%aicrowd login
Please login here: https://api.aicrowd.com/auth/cbvf76iXS5k5TR0Y1sLParTPM-FZWg6hljxapmZTMho
API Key valid
Saved API Key successfully!

Download Dataset¶

We will create a folder name data and download the files there.

In [ ]:
!rm -rf data
!mkdir data
%aicrowd ds dl -c age-prediction -o data
In [ ]:
!unzip data/train.zip -d data/train > /dev/null
!unzip data/val.zip -d data/val > /dev/null
!unzip data/test.zip -d data/test > /dev/null
unzip:  cannot find or open data/test.zip, data/test.zip.zip or data/test.zip.ZIP.

Importing Libraries:

In [ ]:
import pandas as pd
import numpy as np
import os

Diving in the dataset 🕵️‍♂️

In [ ]:
train_df = pd.read_csv("data/train.csv")
val_df = pd.read_csv("data/val.csv")
In [ ]:
test_df = pd.read_csv("data/test.csv")
╭──────────────────────────── Traceback (most recent call last) ────────────────────────────╮
                                                                                           
 /usr/local/lib/python3.7/dist-packages/IPython/core/interactiveshell.py:2882 in run_code  
                                                                                           
   2879 │   │   │   try:                                                                   
   2880 │   │   │   │   self.hooks.pre_run_code_hook()                                     
   2881 │   │   │   │   #rprint('Running code', repr(code_obj)) # dbg                      
 2882 │   │   │   │   exec(code_obj, self.user_global_ns, self.user_ns)                  
   2883 │   │   │   finally:                                                               
   2884 │   │   │   │   # Reset our crash handler in place                                 
   2885 │   │   │   │   sys.excepthook = old_excepthook                                    
 <ipython-input-8-60348e969ddc>:1 in <module>                                              
                                                                                           
 /usr/local/lib/python3.7/dist-packages/pandas/util/_decorators.py:311 in wrapper          
                                                                                           
   308 │   │   │   │   │   FutureWarning,                                                  
   309 │   │   │   │   │   stacklevel=stacklevel,                                          
   310 │   │   │   │   )                                                                   
 311 │   │   │   return func(*args, **kwargs)                                            
   312 │   │                                                                               
   313 │   │   return wrapper                                                              
   314                                                                                     
                                                                                           
 /usr/local/lib/python3.7/dist-packages/pandas/io/parsers/readers.py:586 in read_csv       
                                                                                           
    583 │   )                                                                              
    584 │   kwds.update(kwds_defaults)                                                     
    585 │                                                                                  
  586 return _read(filepath_or_buffer, kwds)                                         
    587                                                                                    
    588                                                                                    
    589 @deprecate_nonkeyword_arguments(                                                   
                                                                                           
 /usr/local/lib/python3.7/dist-packages/pandas/io/parsers/readers.py:482 in _read          
                                                                                           
    479 │   _validate_names(kwds.get("names", None))                                       
    480 │                                                                                  
    481 │   # Create the parser.                                                           
  482 parser = TextFileReader(filepath_or_buffer, **kwds)                            
    483 │                                                                                  
    484 │   if chunksize or iterator:                                                      
    485 │   │   return parser                                                              
                                                                                           
 /usr/local/lib/python3.7/dist-packages/pandas/io/parsers/readers.py:811 in __init__       
                                                                                           
    808 │   │   if "has_index_names" in kwds:                                              
    809 │   │   │   self.options["has_index_names"] = kwds["has_index_names"]              
    810 │   │                                                                              
  811 │   │   self._engine = self._make_engine(self.engine)                              
    812 │                                                                                  
    813 │   def close(self):                                                               
    814 │   │   self._engine.close()                                                       
                                                                                           
 /usr/local/lib/python3.7/dist-packages/pandas/io/parsers/readers.py:1040 in _make_engine  
                                                                                           
   1037 │   │   │   │   f"Unknown engine: {engine} (valid options are {mapping.keys()})"   
   1038 │   │   │   )                                                                      
   1039 │   │   # error: Too many arguments for "ParserBase"                               
 1040 │   │   return mapping[engine](self.f, **self.options)  # type: ignore[call-arg]   
   1041 │                                                                                  
   1042 │   def _failover_to_python(self):                                                 
   1043 │   │   raise AbstractMethodError(self)                                            
                                                                                           
 /usr/local/lib/python3.7/dist-packages/pandas/io/parsers/c_parser_wrapper.py:51 in        
 __init__                                                                                  
                                                                                           
    48 │   │   kwds["usecols"] = self.usecols                                              
    49 │   │                                                                               
    50 │   │   # open handles                                                              
  51 │   │   self._open_handles(src, kwds)                                               
    52 │   │   assert self.handles is not None                                             
    53 │   │                                                                               
    54 │   │   # Have to pass int, would break tests using TextReader directly otherwise : 
                                                                                           
 /usr/local/lib/python3.7/dist-packages/pandas/io/parsers/base_parser.py:229 in            
 _open_handles                                                                             
                                                                                           
    226 │   │   │   compression=kwds.get("compression", None),                             
    227 │   │   │   memory_map=kwds.get("memory_map", False),                              
    228 │   │   │   storage_options=kwds.get("storage_options", None),                     
  229 │   │   │   errors=kwds.get("encoding_errors", "strict"),                          
    230 │   │   )                                                                          
    231 │                                                                                  
    232 │   def _validate_parse_dates_presence(self, columns: list[str]) -> None:          
                                                                                           
 /usr/local/lib/python3.7/dist-packages/pandas/io/common.py:707 in get_handle              
                                                                                           
   704 │   │   │   │   ioargs.mode,                                                        
   705 │   │   │   │   encoding=ioargs.encoding,                                           
   706 │   │   │   │   errors=errors,                                                      
 707 │   │   │   │   newline="",                                                         
   708 │   │   │   )                                                                       
   709 │   │   else:                                                                       
   710 │   │   │   # Binary mode                                                           
╰───────────────────────────────────────────────────────────────────────────────────────────╯
FileNotFoundError: [Errno 2] No such file or directory: 'data/test.csv'
In [ ]:
train_df.head()
train_df.shape
Out[ ]:
(4000, 2)

Generating Prediction File

In this starter kit we will directly be submitting the sample prediction file. In case you would like to see a submission via baseline model, check it out here.

In [ ]:
submission = pd.read_csv('data/sample_submission.csv')
In [ ]:
!rm -rf assets
!mkdir assets
submission.to_csv(os.path.join("assets", "submission.csv"))

Submitting our Predictions

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

In [ ]:
%aicrowd notebook submit -c age-prediction -a assets --no-verify
Using notebook: Copy of Getting Starter Kit for Sentiment Classification  for submission...
Scrubbing API keys from the notebook...
Collecting notebook...


                                                  ╭─────────────────────────╮                                                  
                                                  │ Successfully submitted! │                                                  
                                                  ╰─────────────────────────╯                                                  
                                                        Important links                                                        
┌──────────────────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│  This submission │ https://www.aicrowd.com/challenges/ai-blitz-xiii/problems/age-prediction/submissions/172624              │
│                  │                                                                                                          │
│  All submissions │ https://www.aicrowd.com/challenges/ai-blitz-xiii/problems/age-prediction/submissions?my_submissions=true │
│                  │                                                                                                          │
│      Leaderboard │ https://www.aicrowd.com/challenges/ai-blitz-xiii/problems/age-prediction/leaderboards                    │
│                  │                                                                                                          │
│ Discussion forum │ https://discourse.aicrowd.com/c/ai-blitz-xiii                                                            │
│                  │                                                                                                          │
│   Challenge page │ https://www.aicrowd.com/challenges/ai-blitz-xiii/problems/age-prediction                                 │
└──────────────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────┘
In [ ]:


Comments

You must login before you can post a comment.

Execute