LoginSignup
30
36

More than 1 year has passed since last update.

ColabにKaggleのデータをダウンロードする

Posted at

ノートPCしか持っていなくGPUが使えないので、Colabを使ってみることにしました。
Colab NotebookでKaggleのデータをダウンロードする手順を以下にメモリました。

1. Kaggle APIをインストール

!pip install kaggle

2. kaggle.jsonを使った認証

kaggleのユーザープロファイルの「Account」タブを開き、「Create API Token」を選択します。
API認証情報を含むファイルkaggle.jsonがダウンロードされます。

以下のセルを実行して、Colabランタイムにkaggle.jsonをアップロードします。

from google.colab import files

uploaded = files.upload()

for fn in uploaded.keys():
  print('User uploaded file "{name}" with length {length} bytes'.format(
      name=fn, length=len(uploaded[fn])))

# Then move kaggle.json into the folder where the API expects to find it.
!mkdir -p ~/.kaggle/ && mv kaggle.json ~/.kaggle/ && chmod 600 ~/.kaggle/kaggle.json

3. Kaggle APIを使ってデータをダウンロード

コンペリスト

!kaggle competitions list

各コンペのDataページにAPIコマンドがあります。これを使用してデータをロードします。

image.png

!kaggle competitions download -c titanic

ColabからKaggleへ結果提出

!kaggle competitions submit titanic -f my_submission.csv -m "comment"

参考情報

30
36
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
30
36