kaggle使用笔记

因为参加了DCASE2018比赛的声学场景分类的子任务,这个比赛有个排行榜是用的kaggle来做的,所以在比赛中,用到过kaggle API,下面是关于kaggle的使用笔记。

kaggle 是什么?

Kaggle是一个数据科学竞赛的平台,很多公司会发布一些接近真实业务的问题,吸引爱好数据科学的人来一起解决。

点击导航栏的 competitions 可以看到有很多比赛,其中正式比赛,一般会有奖金或者工作机会,除了正式比赛还有一些为初学者提供的 playground,在这里可以先了解这个比赛,练习能力,再去参加正式比赛。

参赛方法

参赛之前,首先需要一个kaggle的账号,激活之后,找到自己感兴趣的competitions,然后选择“join competitions”即可。

界面介绍:

  • Overview: 首先在 overview 中仔细阅读问题的描述,这个比赛是让我们预测房价,它会给我们 79 个影响房价的变量,我们可以通过应用 random forest,gradient boosting 等算法,来对房价进行预测。

  • Data:在这里给我们提供了 train 数据集,用来训练模型;test 数据集,用来将训练好的模型应用到这上面,进行预测,这个结果也是要提交到系统进行评价的;sample_submission 就是我们最后提交的 csv 文件中,里面的列的格式需要和这里一样。

  • Kernels:可以看到一些参赛者分享的代码。

  • Discussion:参赛者们可以在这里提问,分享经验。

  • Leaderboard:就是参赛者的排行榜。

参赛流程

第一步:在 Data 里面下载三个数据集,最基本的就是上面提到的三个文件,有些比赛会有附加的数据描述文件等。

第二步:自己在线下分析,建模,调参,把用 test 数据集预测好的结果,按照 sample_submission 的格式输出到 csv 文件中。

第三步:点击蓝色按钮 ’Submit Predictions’ ,把 csv 文件拖拽进去,然后系统就会加载并检验结果,稍等片刻后就会在 Leaderboard 上显示当前结果所在的排名位置。
上传过一次结果之后,就直接加入了这场比赛。

注意:正式比赛中每个团队每天有 5 次的上传机会,然后就要等 24 小时再次传结果,playground 的是 9 次。

kaggle API的安装及使用

安装方法

首先确保安装了Python和包管理器pip。

运行以下命令以使用命令行访问Kaggle API:

1
2
3
4
// Windows系统,默认的安装目录是“$ PYTHON_HOME / Scripts”
pip install kaggle
// Mac / Linux系统
pip install --user kaggle

下载API credentials

  • 要使用Kaggle API,需要在kaggle官网上注册Kaggle帐户。

  • 转到用户个人资料的’Account’标签,然后选择“create API Token”之后会弹出kaggle.json的下载,这是一个包含API credentials的文件。

  • 将此文件放在〜/ .kaggle / kaggle.json位置(在Windows上的位置C:\ Users \ <Windows-username> \ .kaggle \ kaggle.json)。

第一次安装的时候,再C:\ Users \ <Windows-username> \ .kaggle \ kaggle.json目录下没有.kaggle这个文件夹,后来通过pip uninstall kaggle再重新安装之后,自动出现.kaggle文件夹,随后直接将kaggle.json文件复制到这个文件夹下面了。

您可以定义一个shell环境变量KAGGLE_CONFIG_DIR来将此位置更改为$ KAGGLE_CONFIG_DIR / kaggle.json(在Windows上它将是%KAGGLE_CONFIG_DIR%\ kaggle.json)。

命令

命令行支持命令:

1
2
3
kaggle competitions {list,files,download,submit,submissions,leaderboard}
kaggle datasets {list, files, download, create, version, init}
kaggle config {view, set, unset}
  • 比赛——API支持Kaggle Competitions的命令

  • List competitions

1
2
3
4
5
6
7
8
9
usage: kaggle competitions list [-h] [-p PAGE] [-s SEARCH] [-v]

optional arguments:
-h, --help show this help message and exit
-p PAGE, --page PAGE page number
-s SEARCH, --search SEARCH
term(s) to search for
-v, --csv print in CSV format
(if not set print in table format)

例子:

1
kaggle competitions list -s health
  • List competition files
1
2
3
4
5
6
7
8
9
usage: kaggle competitions files [-h] [-c COMPETITION] [-v] [-q]

optional arguments:
-h, --help show this help message and exit
-c COMPETITION, --competition COMPETITION
Competition URL suffix (use "kaggle competitions list" to show options)
If empty, the default competition will be used (use "kaggle config set competition")"
-v, --csv Print results in CSV format (if not set print in table format)
-q, --quiet Suppress printing information about download progress

例子:

1
kaggle competitions files -c favorita-grocery-sales-forecasting
  • Download competition files
1
2
3
4
5
6
7
8
9
10
11
12
13
14
usage: kaggle competitions download [-h] [-c COMPETITION] [-f FILE] [-p PATH]
[-w] [-o] [-q]

optional arguments:
-h, --help show this help message and exit
-c COMPETITION, --competition COMPETITION
Competition URL suffix (use "kaggle competitions list" to show options)
If empty, the default competition will be used (use "kaggle config set competition")"
-f FILE, --file FILE File name, all files downloaded if not provided
(use "kaggle competitions files -c <competition>" to show options)
-p PATH, --path PATH Folder where file(s) will be downloaded, defaults to ~/.kaggle
-w, --wp Download files to current working path
-o, --force Skip check whether local version of file is up to date, force file download
-q, --quiet Suppress printing information about download progress

例子:

1
2
kaggle competitions download -c favorita-grocery-sales-forecasting
kaggle competitions download -c favorita-grocery-sales-forecasting -f test.csv.7z
  • Submit to a competition
1
2
3
4
5
6
7
8
9
10
11
12
13
14
usage: kaggle competitions submit [-h] [-c COMPETITION] -f FILE -m MESSAGE
[-q]

required arguments:
-f FILE, --file FILE File for upload (full path)
-m MESSAGE, --message MESSAGE
Message describing this submission

optional arguments:
-h, --help show this help message and exit
-c COMPETITION, --competition COMPETITION
Competition URL suffix (use "kaggle competitions list" to show options)
If empty, the default competition will be used (use "kaggle config set competition")"
-q, --quiet Suppress printing information about download progress

例子:

1
kaggle competitions submit -c favorita-grocery-sales-forecasting -f sample_submission_favorita.csv.7z -m "My submission message"
  • List competition submissions
1
2
3
4
5
6
7
8
9
usage: kaggle competitions submissions [-h] [-c COMPETITION] [-v] [-q]

optional arguments:
-h, --help show this help message and exit
-c COMPETITION, --competition COMPETITION
Competition URL suffix (use "kaggle competitions list" to show options)
If empty, the default competition will be used (use "kaggle config set competition")"
-v, --csv Print results in CSV format (if not set print in table format)
-q, --quiet Suppress printing information about download progress

例子:

1
kaggle competitions submissions -c favorita-grocery-sales-forecasting
  • Get competition leaderboard
1
2
3
4
5
6
7
8
9
10
11
12
usage: kaggle competitions leaderboard [-h] [-c COMPETITION] [-s] [-d]
[-p PATH] [-q]

optional arguments:
-h, --help show this help message and exit
-c COMPETITION, --competition COMPETITION
Competition URL suffix (use "kaggle competitions list" to show options)
If empty, the default competition will be used (use "kaggle config set competition")"
-s, --show Show the top of the leaderboard
-d, --download Download entire leaderboard
-p PATH, --path PATH Folder where file(s) will be downloaded, defaults to ~/.kaggle
-q, --quiet Suppress printing information about download progress

例子:

1
kaggle competitions leaderboard -c favorita-grocery-sales-forecasting -s

数据集——API支持以下用于Kaggle数据集的命令。

  • List datasets
1
2
3
4
5
6
7
8
usage: kaggle datasets list [-h] [-p PAGE] [-s SEARCH] [-v]

optional arguments:
-h, --help show this help message and exit
-p PAGE, --page PAGE Page number for results paging
-s SEARCH, --search SEARCH
Term(s) to search for
-v, --csv Print results in CSV format (if not set print in table format)

例子:

1
kaggle datasets list -s demographics
  • List files for a dataset
1
2
3
4
5
6
7
8
9
usage: kaggle datasets files [-h] -d DATASET [-v]

required arguments:
-d DATASET, --dataset DATASET
Dataset URL suffix in format <owner>/<dataset-name> (use "kaggle datasets list" to show options)

optional arguments:
-h, --help show this help message and exit
-v, --csv Print results in CSV format (if not set print in table format)

例子:

1
kaggle datasets files -d zillow/zecon
  • Download dataset files
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
usage: kaggle datasets download [-h] -d DATASET [-f FILE] [-p PATH] [-w] [-o]
[-q]

required arguments:
-d DATASET, --dataset DATASET
Dataset URL suffix in format <owner>/<dataset-name> (use "kaggle datasets list" to show options)

optional arguments:
-h, --help show this help message and exit
-f FILE, --file FILE File name, all files downloaded if not provided
(use "kaggle datasets files -d <dataset>" to show options)
-p PATH, --path PATH Folder where file(s) will be downloaded, defaults to ~/.kaggle
-w, --wp Download files to current working path
-o, --force Skip check whether local version of file is up to date, force file download
-q, --quiet Suppress printing information about download progress

例子:

1
2
3
kaggle datasets download -d zillow/zecon

kaggle datasets download -d zillow/zecon -f State_time_series.csv
  • Initialize metadata file for dataset creation
1
2
3
4
5
6
7
8
usage: kaggle datasets init [-h] -p FOLDER

required arguments:
-p FOLDER, --path FOLDER
Folder for upload, containing data files and a special metadata.json file (https://github.com/Kaggle/kaggle-api/wiki/Metadata)

optional arguments:
-h, --help show this help message and exit

例子:

1
kaggle datasets init -p /path/to/dataset
  • Create a new dataset
1
2
3
4
5
6
7
8
9
10
11
usage: kaggle datasets create [-h] -p FOLDER [-u] [-q]

required arguments:
-p FOLDER, --path FOLDER
Folder for upload, containing data files and a special metadata.json file (https://github.com/Kaggle/kaggle-api/wiki/Metadata)

optional arguments:
-h, --help show this help message and exit
-u, --public Create the Dataset publicly (default is private)
-q, --quiet Suppress printing information about download progress
-t, --keep-tabular Do not convert tabular files to CSV (default is to convert)

例子:

1
kaggle datasets create -p /path/to/dataset
  • Create a new dataset version
1
2
3
4
5
6
7
8
9
10
11
12
13
14
usage: kaggle datasets version [-h] -m VERSION_NOTES -p FOLDER [-q]

required arguments:
-m VERSION_NOTES, --message VERSION_NOTES
Message describing the new version
-p FOLDER, --path FOLDER
Folder for upload, containing data files and a special metadata.json file (https://github.com/Kaggle/kaggle-api/wiki/Metadata)

optional arguments:
-h, --help show this help message and exit
-q, --quiet Suppress printing information about download progress
-t, --keep-tabular Do not convert tabular files to CSV (default is to convert)
-d, --delete-old-versions
Delete old versions of this dataset

例子:

1
kaggle datasets version -p /path/to/dataset -m "Updated data"

配置

  • View current config values
1
2
3
4
5
6
7
8
9
10
11
12
13
14
usage: kaggle config path [-h] [-p PATH]

optional arguments:
-h, --help show this help message and exit
-p PATH, --path PATH folder where file(s) will be downloaded, defaults to ~/.kaggle
Example:

kaggle config path -p C:\

View current config values
usage: kaggle config view [-h]

optional arguments:
-h, --help show this help message and exit

例子:

1
kaggle config view
  • Set a configuration value
1
2
3
4
5
6
7
8
9
10
usage: kaggle config set [-h] -n NAME -v VALUE

required arguments:
-n NAME, --name NAME Name of the configuration parameter
(one of competition, path, proxy)
-v VALUE, --value VALUE
Value of the configuration parameter, valid values depending on name
- competition: Competition URL suffix (use "kaggle competitions list" to show options)
- path: Folder where file(s) will be downloaded, defaults to ~/.kaggle
- proxy: Proxy for HTTP requests

例子:

1
kaggle config set -n competition -v titanic
  • Clear a configuration value
1
2
3
4
5
usage: kaggle config unset [-h] -n NAME

required arguments:
-n NAME, --name NAME Name of the configuration parameter
(one of competition, path, proxy)

例子:

1
kaggle config unset -n competition

注意:目前最大的限制是此时不以任何方式支持内核。 我们打算在不久的将来实施支持,尽管没有ETA。 此外,目前无法使用大型数据集(> = 2GB)。

参考

  1. kaggle官网
  2. kaggle API
  3. 从0到1走进 Kaggle
  4. 一个框架解决几乎所有机器学习问题
  5. Kaggle比赛:从何着手?
  6. kaggle入门(python数据处理)

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/242265.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

PHP简单功能的实现

检查一个变量是否为空empty功能返回值&#xff1a;若变量不存在则返回 TRUE若变量存在且其值为””、0、”0”、NULL、FALSE、 array()、var $var; 以及没有任何属性的对象&#xff0c;则返回 TURE若变量存在且值不为””、0、”0”、NULL、FALSE、 array()、var $var; 以及没有…

C#流和文件

C#流和文件 文件及文件夹管理 WinForm中的文件对话框 文件内容的读写 注册表操作

PHP操作MySQL数据库(连接、增删改操作)

MySQL 是跟 PHP 配套使用的最流行的开源数据库系统&#xff0c;我们知道MySQL是PHP的最佳搭档&#xff0c;下面是系统的总结PHP与MySQL联合使用的方法。主要是使用MySQL扩展&#xff0c;下面就通过归纳总结来提升。 MySQL概述MySQL 是一种在 Web 上使用的数据库系统。 MySQL 是…

互联网应届生四项职场生存技能

职场能力一&#xff1a;沟通力沟通力是职场最重要也是最基础的一项能力。 进入职场后&#xff0c;无论从事什么岗位都必然要用到沟通力这个能力项。沟通力有一个很重要的基石&#xff0c;就是尊重对方的时间。每一次沟通&#xff0c;双方其实都要投入很多时间和精力。只有懂得尊…

C#中程序错误的种类和程序的调试

C#中程序错误的种类 语法错误 运行错误 逻辑错误 程序调试的基本手段 然后运行 调试程序例子 例子2&#xff1a;读文件 没有找到文件 null引用就是没有进行初始化 索引超出数组界限

缓存

最近在狂补优化方面的知识&#xff0c;缓存也是优化的一大方向。之前关于缓存只是知道它的功能&#xff0c;再多不知道了&#xff0c;这里整理缓存相关的知识&#xff0c;算是优化入门吧。 相关概念缓存 是“存贮使用频繁的数据的临时地方&#xff0c;因为取原始数据的代价太大…

mysql中as用法

重命名列名或者表名。as可理解为&#xff1a;用作、当成&#xff0c;作为&#xff1b;一般是重命名列名或者表名。&#xff08;主要为了查询方便&#xff09; 重命名列。如&#xff1a;表text&#xff0c; 列 column_1,column_2 你可以写成&#xff1a; 1select column_1 as …

C#中window窗体和控件

C#中window窗体和控件 布局与事件–界面的基本问题 布局 就是拉动窗体的时候&#xff0c;按钮也在跟着变动。 事件 //简单的计算器 using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; namespa…

PHP自动加载机制

概述首先&#xff0c;为什么PHP需要自动加载呢&#xff1f; 在PHP面向对象(OO)编程中&#xff0c;为了方便管理&#xff0c;我们都会把一个类写在一个单独的文件中&#xff0c;那么如果想在A类中使用B类的功能&#xff0c;就需要把B类加载到A类。对于这样的需求在最原始的时候&…

操作系统知识——互斥和死锁

银行家算法银行家算法是最有代表性的避免死锁算法&#xff0c;是Dijkstra提出的。这是由于该算法能用于银行系统现金贷款的发放而得名。 我们可以把操作系统看作是银行家&#xff0c;操作系统管理的资源相当于银行家管理的资金&#xff0c;进程向操作系统请求分配资源相当于用户…

C#常用的控件

C#常用的控件 窗体 菜单、工具栏、对话框 用户控件及控件的继承

C++输入函数的应用

最近因为找工作的事情&#xff0c;在刷一些编程题&#xff0c;也陆陆续续参加了一些笔试&#xff0c;一般编程中使用的语言是C&#xff0c;因为编程题会有时间的限制&#xff0c;C的效率最高&#xff0c;不容易出现超时的问题所以使用最多的语言就是C。 在编程中&#xff0c;其…

C#绘图及图像

C#绘图及图像 绘图的基本方法 绘图的应用

PHP开发API

引言如何使用 PHP 开发 API&#xff08;Application Programming Interface&#xff0c;应用程序编程接口&#xff09; 呢&#xff1f; 做过 API 的人应该了解&#xff0c;其实开发 API 比开发 WEB 更简洁&#xff0c;但可能逻辑更复杂&#xff0c;因为 API 其实就是数据输出&a…

热部署和热加载

2018-8-22今天入职第二天&#xff0c;看到老大在群里发了一个go热加载实现的链接&#xff0c;之前没有听说过热加载&#xff0c;所以搜索了一下&#xff0c;下面是关于热部署和热加载的相关整理。 引言在项目线上更新时&#xff0c;可能会遇到需要热部署的情况&#xff0c;虽然…

C#实现定时器

C#实现定时器 方法一 布局 代码 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;namespace…

HTTP请求流程

hhtp请求流程首先http是一个应用层的协议&#xff0c;在这个层的协议&#xff0c;只是一种通讯规范&#xff0c;也就是因为双方要进行通讯&#xff0c;大家要事先约定一个规范。 http请求与响应的步骤如下&#xff1a; URL解析、域名解析 输入URL的时候&#xff0c;首先浏览器会…

PHP执行外部程序的方法

引言在一些特殊情况下&#xff0c;会使用PHP调用外部程序执行&#xff0c;比如&#xff1a;调用shell命令、shell脚本、可执行程序等等 PHP执行外部程序的方法 system()&#xff0c;system函数将执行的结果直接输出exec()&#xff1a;执行一个外部程序&#xff0c;将输出结果保…

C语言函数变量的引用

C语言函数变量的引用 有时候&#xff0c;你想引用函数中的某些变量。 #include <stdio.h>int main() {struct guoba{int pang;int piqi;};void tong(int *p){int month1 3;int month5 8;struct guoba xiaoguoba;xiaoguoba.pang month1 month5;*p xiaoguoba.pang ;…

php 终止程序的方法——return、exit()、die()

php中终止程序的运行有三种方式&#xff1a; return&#xff0c;主脚本程序中使用exit()&#xff0c;脚本中使用die()&#xff0c; 脚本中使用三者所在的脚本文件他们之后的代码都不会执行了。php开发模式下想直接看到变量的值使用exit()、die()。 returnreturn是语言结构而不是…