Using Kaggle Datasets in Google Colab

前端 未结 8 1752
南笙
南笙 2020-11-30 22:11

Is it possible to use any datasets available via the kaggle API in Google Colab? I see the Kaggle API is used in this Colab notebook, but it\'s a bit unclear to

8条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-30 22:19

    Combined the top response to this Github gist as Colab Implementation. You can directly copy the code and use it.

    How to Import a Dataset from Kaggle in Colab

    Method:

    First a few things you have to do:

    1. Sign up for Kaggle
    2. Sign up for a competition you want to access data from (for example LANL-Earthquake-Prediction competition).
    3. Download your credentials to access Kaggle API as kaggle.json
    # Install kaggle packages
    !pip install -q kaggle
    !pip install -q kaggle-cli
    
    # Colab's file access feature
    from google.colab import files
    
    # Upload `kaggle.json` file
    uploaded = files.upload()
    
    # Retrieve uploaded file
    # print results
    for fn in uploaded.keys():
      print('User uploaded file "{name}" with length {length} bytes'.format(
          name=fn, length=len(uploaded[fn])))
    
    # Then copy kaggle.json into the folder where the API expects to find it.
    !mkdir -p ~/.kaggle
    !cp kaggle.json ~/.kaggle/
    !chmod 600 ~/.kaggle/kaggle.json
    !ls ~/.kaggle
    

    Now check if it worked!

    #list competitions
    !kaggle competitions list -s LANL-Earthquake-Prediction
    

提交回复
热议问题