DarkMatter in Cyberspace
  • Home
  • Categories
  • Tags
  • Archives

Submit Competition Task with Kaggle API


Setup

配置 API 开发环境,包括准备 API token, 安装 Kaggle API 工具和 jupytext 转换工具。

In My Account click "Create New API Token" download file kaggle.json, put it into ~/.kaggle.

chmod 600 ~/.kaggle/kaggle.json
cd ~/docs/kapi
. env/bin/activate   # or conda activate tfgpu
pip install kaggle

Work flow

Google 搜索 kaggle competition how to submit,找到 notebook Complete Beginner: Your First Titanic Submission, 下面以此为例说明使用 Kaggle API 完成一次竞赛提交的完整过程。

My Profile -> Competitions 下面为空。

通过模糊搜索查找竞赛名称: competitions list -s house-price

准备 kernel

列出一个 competition 下得分最高的 kernels:

kaggle kernels list --competition house-prices-advanced-regression-techniques --sort-by voteCount

或者把 --sort-by 的值改成 voteCount 即按票数从多到少排列。

也可以使用模糊搜索:

kaggle kernels list -s house-prices --sort-by scoreAscending

也可以从网页 URL 中提取 kernel slug: jlawman/complete-beginner-your-first-titanic-submission

用 slug 下载 kernel 到项目根目录 titanic 中:

kaggle kernels pull jlawman/complete-beginner-your-first-titanic-submission -p titanic -m

可以用 kaggle kernels list -s titanic --user jlawman 输出的 ref 字段验证 slug。

准备数据文件

kaggle competitions download titanic -p titanic/input
cd titanic/input
unzip titanic.zip

可以用 kaggle competitions files titanic 列出数据文件, 确认之后再用 download 命令下载。

转换 notebook 为 python 脚本

安装 jupytext,将 .ipynb 文件转换为 .py 脚本:

cd ..      # back to code folder, $ROOT/demo
jupytext --to py complete-beginner-your-first-titanic-submission.ipynb

修改、调试、运行并得到输出

在 IPython Console 中调试运行 .py 脚本。

例如修改输入文件路径,将 .py 文件中 ../input/ 改为 ./input, 运行脚本 python complete-beginner-your-first-titanic-submission.py, 得到输出文件 Titanic Predictions 1.csv。

提交结果文件

确认竞赛名称: kaggle competitions list -s titanic

打开 https://www.kaggle.com/c/titanic/rules 确认竞赛规则。

export http_proxy=http://localhost:1080 https_proxy=http://localhost:1080
kaggle competitions submit titanic -f submission.csv -m "submit from kaggle api by Leo, jul 4"

The proxy is only for where Google is banned. See Kaggle API issue #113 for details.

提交成功后输出 Successfully submitted to House Prices: Advanced Regression Techniques。 在 My Profile > Competitions 可以看到 Titanic 竞赛和自己的排名,点击竞赛链接,进入竞赛主页, 例如 Titanic, 在竞赛主页的 "My Submissions" 下就可以看到提交了, 点击下面的 "Jump to your position on the leaderboard" 链接, 可以看到自己所在 team 在 leaderboard 里的排名。

通过与 House Prices: Advanced Regression Techniques 对比,可以看到我在 Titanic 的 leaderboard 是单人 team, 而在 house price 的 leaderboard 包含3个用户, 是之前在这个竞赛的 Team 标签页下配置好的 SLM。

提交 kernel

kaggle kernels push -p titanic
kaggle kernels status sharon89/kernel3bdf189a6b


Published

Jul 4, 2020

Last Updated

Jul 4, 2020

Category

Tech

Tags

  • api 3
  • kaggle 1
  • submit 2

Contact

  • Powered by Pelican. Theme: Elegant by Talha Mansoor