LoginSignup
2
1

More than 1 year has passed since last update.

kaggleコンペのデータ取得 (Google Colaboratory)

Last updated at Posted at 2021-06-25

背景

Kaggle大会データの取得方法を備忘録として残します。
今回ダウンロードするのは、siim-covid19-detectionコンペです。
本コンペに含まれる画像がdcmという拡張子なので見方についてもアップ予定です。

環境準備

# kaggle APIのインストール
!pip install kaggle
#ドライブの準備
from google.colab import drive
drive.mount('/content/drive/')

!mkdir -p '/content/drive/My Drive/data/kaggle'
%cd '/content/drive/My Drive/data/kaggle'
これはコマンドじゃないよ、ブラウザから実施。
# kaggle API用のAPIキーの取得
kaggleの右上にある自身のアイコンをクリック
Accountをクリック
APIのCreate New API Tokenをクリックして、kaggle.jsonをローカル保存
# kaggle API用のAPIキーのセット
from google.colab import files
uploaded = files.upload()  #kaggle.jsonをアップロード
for fn in uploaded.keys():
  print('User uploaded file "{name}" with length {length} bytes'.format(
      name=fn, length=len(uploaded[fn])))

!mkdir -p ~/.kaggle/ 
!mv kaggle.json ~/.kaggle/ 
!chmod 600 ~/.kaggle/kaggle.json
# 大会一覧の表示
!kaggle competitions list

任意の大会データ取得

これはコマンドじゃないよ、ブラウザから実施。
## データ利用に合意
kaggleの大会ページから、Join Conpetitionでデータの取り扱い等に合意
## ダウンロード
%cd '/content/drive/My Drive/data/kaggle'
!mkdir siim-covid19-detection
%cd siim-covid19-detection
!kaggle competitions download -c siim-covid19-detection
2
1
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
2
1