kaggle API

2018-04-27  本文已影响3073人  Miliimoulins

参考官方:https://github.com/Kaggle/kaggle-api

Install

conda install pip
pip install kaggle

To use the Kaggle API, sign up for a Kaggle account at https://www.kaggle.com. Then go to the 'Account' tab of your user profile (https://www.kaggle.com/<username>/account) and select 'Create API Token'. This will trigger the download of kaggle.json, a file containing your API credentials. Place this file in the location ~/.kaggle/kaggle.json (on Windows in the location C:\Users\<Windows-username>\.kaggle\kaggle.json).

For your security, ensure that other users of your computer do not have read access to your credentials. On Unix-based systems you can do this with the following command:
chmod 600 ~/.kaggle/kaggle.json

Example

1、列出属于Health这一类的所有比赛

kaggle competitions list -s health
ref                                        deadline             category      reward  teamCount  userHasEntered  
-----------------------------------------  -------------------  --------  ----------  ---------  --------------  
hhp                                        2013-04-04 07:00:00  Featured    $500,000       1353           False  
ultrasound-nerve-segmentation              2016-08-18 23:59:00  Featured    $100,000        923           False  
diabetic-retinopathy-detection             2015-07-27 23:59:00  Featured    $100,000        661            True  
msk-redefining-cancer-treatment            2017-10-02 23:59:00  Research     $15,000       1386           False  
second-annual-data-science-bowl            2016-03-14 23:59:00  Featured    $200,000        773           False  
melbourne-university-seizure-prediction    2016-12-01 23:59:00  Research     $20,000        478           False  
data-science-bowl-2017                     2017-04-12 23:59:00  Featured  $1,000,000       1972            True  
intel-mobileodt-cervical-cancer-screening  2017-06-21 23:59:00  Featured    $100,000        848           False  
mens-machine-learning-competition-2018     2018-04-02 23:59:00  Featured     $50,000        934           False  
march-machine-learning-mania-2014          2014-04-08 23:59:00  Featured     $15,000        248           False  

2、下载 <competition_name> 下的Data中所有文件,指定下载路径<path>

kaggle competitions download -c <competition_name> -p <path>

3、下载 <competition_name>下的Data中某个文件 <filename>,指定下载路径<path>

kaggle competitions download -c <competition_name> -f <filename> -p <path>

例:kaggle competitions download -c diabetic-retinopathy-detection -f trainLabels.csv.zip -p /Users/httbser/Datasets/kaggle/DR
4、提交结果

usage: kaggle competitions submit [-h] [-c COMPETITION] -f FILE -m MESSAGE
                                  [-q]

required arguments:
  -f FILE, --file FILE  File for upload (full path)
  -m MESSAGE, --message MESSAGE
                        Message describing this submission

optional arguments:
  -h, --help            show this help message and exit
  -c COMPETITION, --competition COMPETITION
                        Competition URL suffix (use "kaggle competitions list" to show options)
                        If empty, the default competition will be used (use "kaggle config set competition")"
  -q, --quiet           Suppress printing information about download progress
kaggle competitions submit -c diabetic-retinopathy-detection -f sample_submission_favorita.csv.7z -m "My submission message"

How to unzip split files

It can also be easily done on the command line.

For example:

cat file.zip.001 > s.zip 
cat file.zip.002 >> s.zip    # pay attention: >>
cat file.zip.003 >> s.zip

unzip s.zip
copy /B input.z* output.zip

BTW, how to split the zip:

You have existing.zip but want to split it into 50M sized parts:

zip existing.zip --out new.zip -s 50m

will create

new.zip
new.z01
new.z02
new.z03
....
上一篇 下一篇

猜你喜欢

热点阅读