$ kaggle --help
Unauthorized: you must download an API key from https://www.kaggle.com/<username>/account
Then put kaggle.json in the folder /Users/u110/.kaggle
とりあえずhelpを見てみようとしたら上記のようなメッセージが。
アカウントの認証が必要とのこと。
ブラウザログインして、上で指定されているURLを開くとAPIという項目がありました。
“Create New API Token” というボタンを押すと kaggle.json がダウンロードできるので、
そのファイルを指定通りに ~/.kaggle ディレクトリ以下に配置します。
$ kaggle --help
Warning: Your Kaggle API key is readable by other users on this system! To fix this, you can run 'chmod 600 /Users/itouyuu/.kaggle/kaggle.json'
usage: kaggle [-h] {competitions,datasets,config} ...
optional arguments:
-h, --help show this help message and exit
commands:
{competitions,datasets,config}
Use one of:
competitions {list, files, download, submit, submissions}
datasets {list, files, download, create, version, init}
config {view, set, unset}
competitions Commands related to Kaggle competitions
datasets Commands related to Kaggle datasets
config Configuration settings
$ chmod 600 ~/.kaggle/kaggle.json
$ kaggle datasets
usage: kaggle datasets [-h] {list,files,download,create,version,init} ...
kaggle datasets: error: the following arguments are required: command
コマンドのヘルプが出ましたね。
chmodでパーミッション変えておいてねとあるのでやっておきましょう。
親切。。!
コンペの参照
$ kaggle competitions list
ref deadline category reward teamCount userHasEntered
----------------------------------------------------------------------------------------------------------------
imagenet-object-detection-challenge 2029-12-31 07:00:00 Research Knowledge 0 False
imagenet-object-detection-from-video-challenge 2029-12-31 07:00:00 Research Knowledge 0 False
imagenet-object-localization-challenge 2029-12-31 07:00:00 Research Knowledge 7 False
titanic 2020-04-07 00:00:00 Getting Started Knowledge 11053 True
house-prices-advanced-regression-techniques 2020-03-01 23:59:00 Getting Started Knowledge 5061 False
digit-recognizer 2020-01-07 00:00:00 Getting Started Knowledge 2242 False
...
データセットのダウンロード
titanicデータをダウンロードしてみましょう。
とりあえすdownloadコマンドのヘルプを叩いてみます。
$ kaggle competitions download --help
usage: kaggle competitions download [-h] [-c COMPETITION] [-f FILE] [-p PATH]
[-w] [-o] [-q]
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")"
-f FILE, --file FILE File name, all files downloaded if not provided
(use "kaggle competitions files -c <competition>" to show options)
-p PATH, --path PATH Folder where file(s) will be downloaded, defaults to /Users/itouyuu/.kaggle
-w, --wp Download files to current working path
-o, --force Skip check whether local version of file is up to date, force file download
-q, --quiet Suppress printing information about download progress
cオプションでコンペ名を指定するようですね。
$ kaggle competitions download -c titanic
train.csv: Downloaded 60KB of 60KB
test.csv: Downloaded 28KB of 28KB
gender_submission.csv: Downloaded 3KB of 3KB
$ ls ~/.kaggle/
competitions/ kaggle.json
$ ls ~/.kaggle/competitions/titanic/
gender_submission.csv test.csv train.csv