在 Google Colab 中使用 Kaggle 数据集 [英] Using Kaggle Datasets in Google Colab

查看:18
本文介绍了在 Google Colab 中使用 Kaggle 数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过 Google Colab 中的 kaggle API 使用任何可用的数据集?我看到

  • 接下来,向下滚动到 API 访问部分并点击生成下载 API 密钥.这会将名为 kaggle.json 的文件下载到您的计算机.您将在 Colab 中使用此文件来访问 Kaggle 数据集和比赛.

  • 导航到 https://colab.research.google.com/.

  • 使用以下代码段上传您的 kaggle.json 文件一个代码单元:

    从 google.colab 导入文件文件.上传()

  • 使用 !pip install -q kaggle

  • 安装 kaggle API
  • kaggle.json 文件移动到 ~/.kaggle 中,这是API 客户端希望您的令牌位于:

    !mkdir -p ~/.kaggle!cp kaggle.json ~/.kaggle/

  • 现在您可以使用客户端访问数据集,例如 !kaggle datasets list.

  • 以下是此过程的 Colab 部分的完整示例笔记本:https://colab.research.google.com/drive/1DofKedQYaXmDWBzuResXWWvxhLgDeVyl

    此示例显示上传 kaggle.json 文件、Kaggle API 客户端以及使用 Kaggle 客户端下载数据集.

    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 me what datasets it provides access to.

    解决方案

    Step-by-step --

    1. Create an API key in Kaggle.

      To do this, go to kaggle.com/ and open your user settings page.

    2. Next, scroll down to the API access section and click generate to download an API key. This will download a file called kaggle.json to your computer. You'll use this file in Colab to access Kaggle datasets and competitions.

    3. Navigate to https://colab.research.google.com/.

    4. Upload your kaggle.json file using the following snippet in a code cell:

      from google.colab import files files.upload()

    5. Install the kaggle API using !pip install -q kaggle

    6. Move the kaggle.json file into ~/.kaggle, which is where the API client expects your token to be located:

      !mkdir -p ~/.kaggle !cp kaggle.json ~/.kaggle/

    7. Now you can access datasets using the client, e.g., !kaggle datasets list.

    Here's a complete example notebook of the Colab portion of this process: https://colab.research.google.com/drive/1DofKEdQYaXmDWBzuResXWWvxhLgDeVyl

    This example shows uploading the kaggle.json file, the Kaggle API client, and using the Kaggle client to download a dataset.

    这篇关于在 Google Colab 中使用 Kaggle 数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆