机器之心报道

机器之心编辑部

igel 是 GitHub 上的一个热门工具,基于 scikit-learn 构建,支持 sklearn 的所有机器学习功能,如回归、分类和聚类。用户无需编写一行代码即可使用机器学习模型,只要有 yaml 或 json 文件,来描述你想做什么即可。

一行代码不用写,就可以训练、测试和使用模型,还有这样的好事?

最近,软件工程师 Nidhal Baccouri 就在 GitHub 上开源了一个这样的机器学习工具——igel,并登上了 GitHub 热榜。目前,该项目 star 量已有 1.5k。

项目地址:https://github.com/nidhaloff/igel

该项目旨在为每一个人(包括技术和非技术人员)提供使用机器学习的便捷方式。

项目作者这样描述创建 igel 的动机:「有时候我需要一个用来快速创建机器学习原型的工具,不管是进行概念验证还是创建快速 draft 模型。我发现自己经常为写样板代码或思考如何开始而犯愁。于是我决定创建 igel。

igel 基于 scikit-learn 构建,支持 sklearn 的所有机器学习功能,如回归、分类和聚类。用户无需编写一行代码即可使用机器学习模型,只要有 yaml 或 json 文件,来描述你想做什么即可。

其基本思路是在人类可读的 yaml 或 json 文件中将所有配置进行分组,包括模型定义、数据预处理方法等,然后让 igel 自动化执行一切操作。用户在 yaml 或 json 文件中描述自己的需求,之后 igel 使用用户的配置构建模型,进行训练,并给出结果和元数据。

igel 目前支持的所有配置如下所示:

# dataset operations
dataset:type: csv  # [str] -> type of your datasetread_data_options: # options you want to supply for reading your data (See the detailed overview about this in the next p)sep:  # [str] -> Delimiter to use.delimiter:  # [str] -> Alias for sep.header:     # [int, list of int] -> Row number(s) to use as the column names, and the start of the data.names:  # [list] -> List of column names to useindex_col: # [int, str, list of int, list of str, False] -> Column(s) to use as the row labels of the DataFrame,usecols:    # [list, callable] -> Return a subset of the columnssqueeze:    # [bool] -> If the parsed data only contains one column then return a Series.prefix:     # [str] -> Prefix to add to column numbers when no header, e.g. ‘X’ for X0, X1, …mangle_dupe_cols:   # [bool] -> Duplicate columns will be specified as ‘X’, ‘X.1’, …’X.N’, rather than ‘X’…’X’. Passing in False will cause data to be overwritten if there are duplicate names in the columns.dtype:  # [Type name, dict maping column name to type] -> Data type for data or columnsengine:     # [str] -> Parser engine to use. The C engine is faster while the python engine is currently more feature-complete.converters: # [dict] -> Dict of functions for converting values in certain columns. Keys can either be integers or column labels.true_values: # [list] -> Values to consider as True.false_values: # [list] -> Values to consider as False.skipinitialspace: # [bool] -> Skip spaces after delimiter.skiprows: # [list-like] -> Line numbers to skip (0-indexed) or number of lines to skip (int) at the start of the file.skipfooter: # [int] -> Number of lines at bottom of file to skipnrows: # [int] -> Number of rows of file to read. Useful for reading pieces of large files.na_values: # [scalar, str, list, dict] ->  Additional strings to recognize as NA/NaN.keep_default_na: # [bool] ->  Whether or not to include the default NaN values when parsing the data.na_filter: # [bool] -> Detect missing value markers (empty strings and the value of na_values). In data without any NAs, passing na_filter=False can improve the performance of reading a large file.verbose: # [bool] -> Indicate number of NA values placed in non-numeric columns.skip_blank_lines: # [bool] -> If True, skip over blank lines rather than interpreting as NaN values.parse_dates: # [bool, list of int, list of str, list of lists, dict] ->  try parsing the datesinfer_datetime_format: # [bool] -> If True and parse_dates is enabled, pandas will attempt to infer the format of the datetime strings in the columns, and if it can be inferred, switch to a faster method of parsing them.keep_date_col: # [bool] -> If True and parse_dates specifies combining multiple columns then keep the original columns.dayfirst: # [bool] -> DD/MM format dates, international and European format.cache_dates: # [bool] -> If True, use a cache of unique, converted dates to apply the datetime conversion.thousands: # [str] -> the thousands operatordecimal: # [str] -> Character to recognize as decimal point (e.g. use ‘,’ for European data).lineterminator: # [str] -> Character to break file into lines.escapechar: # [str] ->  One-character string used to escape other characters.comment: # [str] -> Indicates remainder of line should not be parsed. If found at the beginning of a line, the line will be ignored altogether. This parameter must be a single character.encoding: # [str] -> Encoding to use for UTF when reading/writing (ex. ‘utf-8’).dialect: # [str, csv.Dialect] -> If provided, this parameter will override values (default or not) for the following parameters: delimiter, doublequote, escapechar, skipinitialspace, quotechar, and quotingdelim_whitespace: # [bool] -> Specifies whether or not whitespace (e.g. ' ' or '    ') will be used as the seplow_memory: # [bool] -> Internally process the file in chunks, resulting in lower memory use while parsing, but possibly mixed type inference.memory_map: # [bool] -> If a filepath is provided for filepath_or_buffer, map the file object directly onto memory and access the data directly from there. Using this option can improve performance because there is no longer any I/O overhead.split:  # split optionstest_size: 0.2  #[float] -> 0.2 means 20% for the test data, so 80% are automatically for trainingshuffle: true   # [bool] -> whether to shuffle the data before/while splittingstratify: None  # [list, None] -> If not None, data is split in a stratified fashion, using this as the class labels.preprocess: # preprocessing optionsmissing_values: mean    # [str] -> other possible values: [drop, median, most_frequent, constant] check the docs for moreencoding:type: oneHotEncoding  # [str] -> other possible values: [labelEncoding]scale:  # scaling optionsmethod: standard    # [str] -> standardization will scale values to have a 0 mean and 1 standard deviation  | you can also try minmaxtarget: inputs  # [str] -> scale inputs. | other possible values: [outputs, all] # if you choose all then all values in the dataset will be scaled# model definition
model:type: classification    # [str] -> type of the problem you want to solve. | possible values: [regression, classification, clustering]algorithm: NeuralNetwork    # [str (notice the pascal case)] -> which algorithm you want to use. | type igel algorithms in the Terminal to know morearguments:          # model arguments: you can check the available arguments for each model by running igel help in your terminaluse_cv_estimator: false     # [bool] -> if this is true, the CV class of the specific model will be used if it is supportedcross_validate:cv: # [int] -> number of kfold (default 5)n_jobs:   # [signed int] -> The number of CPUs to use to do the computation (default None)verbose: # [int] -> The verbosity level. (default 0)# target you want to predict
target:  # list of strings: basically put here the column(s), you want to predict that exist in your csv dataset- put the target you want to predict here- you can assign many target if you are making a multioutput prediction

这款工具具备以下特性:

  • 支持所有机器学习 SOTA 模型(甚至包括预览版模型);

  • 支持不同的数据预处理方法;

  • 既能写入配置文件,又能提供灵活性和数据控制;

  • 支持交叉验证;

  • 支持 yaml 和 json 格式;

  • 支持不同的 sklearn 度量,进行回归、分类和聚类;

  • 支持多输出 / 多目标回归和分类;

  • 在并行模型构建时支持多处理。

如前所示,igel 支持回归、分类和聚类模型,包括我们熟悉的线性回归、贝叶斯回归、支持向量机、Adaboost、梯度提升等。

igel 支持的回归、分类和聚类模型。

快速入门

为了让大家快速上手 igel,项目作者在「README」文件中提供了详细的入门指南。

运行以下命令可以获取 igel 的帮助信息:

$ igel --help# or just$ igel -h"""Take some time and read the output of help command. You ll save time later if you understand how to use igel."""

第一步是提供一份 yaml 文件(你也可以使用 json)。你可以手动创建一个. yaml 文件并自行编辑。但如何你很懒,也可以选择使用 igel init 命令来快速启动:

"""igel init <args>possible optional args are: (notice that these args are optional, so you can also just run igel init if you want)-type: regression, classification or clustering-model: model you want to use-target: target you want to predictExample:If I want to use neural networks to classify whether someone is sick or not using the indian-diabetes dataset,then I would use this command to initliaze a yaml file:
$ igel init -type "classification" -model "NeuralNetwork" -target "sick""""
$ igel init

运行该命令之后,当前的工作目录中就有了一个 igel.yaml 文档。你可以检查这个文件并进行修改,也可以一切从头开始。

在下面这个例子中,作者使用随机森林来判断一个人是否患有糖尿病。他用到的数据集是著名的「Pima Indians Diabetes Database」。

# model definitionmodel:# in the type field, you can write the type of problem you want to solve. Whether regression, classification or clustering# Then, provide the algorithm you want to use on the data. Here I'm using the random forest algorithmtype: classificationalgorithm: RandomForest     # make sure you write the name of the algorithm in pascal casearguments:n_estimators: 100   # here, I set the number of estimators (or trees) to 100max_depth: 30       # set the max_depth of the tree# target you want to predict# Here, as an example, I'm using the famous indians-diabetes dataset, where I want to predict whether someone have diabetes or not.# Depending on your data, you need to provide the target(s) you want to predict heretarget:- sick

注意,作者将 n_estimators 和 max_depth 传递给了模型,用作模型的附加参数。如果你不提供参数,模型就会使用默认参数。你不需要记住每个模型的参数。相反,你可以在终端运行 igel models 进入交互模式。在交互模式下,系统会提示你输入你想要使用的模型以及你想要解决的问题的类型。接下来,Igel 将展示出有关模型的信息和链接。通过该链接,你可以看到可用参数列表以及它们的使用方法。

igel 的使用方式应该是从终端(igel CLI):

在终端运行以下命令来拟合 / 训练模型,你需要提供数据集和 yaml 文件的路径。

$ igel fit --data_path 'path_to_your_csv_dataset.csv' --yaml_file 'path_to_your_yaml_file.yaml'# or shorter$ igel fit -dp 'path_to_your_csv_dataset.csv' -yml 'path_to_your_yaml_file.yaml'"""That's it. Your "trained" model can be now found in the model_results folder(automatically created for you in your current working directory).Furthermore, a description can be found in the description.json file inside the model_results folder."""

接下来,你可以评估训练 / 预训练好的模型:

$ igel evaluate -dp 'path_to_your_evaluation_dataset.csv'"""This will automatically generate an evaluation.json file in the current directory, where all evaluation results are stored"""

如果你对评估结果比较满意,就可以使用这个训练 / 预训练好的模型执行预测。

$ igel predict -dp 'path_to_your_test_dataset.csv'"""This will generate a predictions.csv file in your current directory, where all predictions are stored in a csv file"""

你可以使用一个「experiment」命令将训练、评估和预测结合到一起:

$ igel experiment -DP "path_to_train_data path_to_eval_data path_to_test_data" -yml "path_to_yaml_file""""This will run fit using train_data, evaluate using eval_data and further generate predictions using the test_data"""

当然,如果你想写代码也是可以的:

交互模式

交互模式是 v0.2.6 及以上版本中新添加的,该模式可以让你按照自己喜欢的方式写参数。

也就是说,你可以使用 fit、evaluate、predict、experiment 等命令而无需指定任何额外的参数,比如:

igel fit

如果你只是编写这些内容并点击「enter」,系统将提示你提供额外的强制参数。0.2.5 及以下版本会报错,所以你需要使用 0.2.6 及以上版本。

如 demo 所示,你不需要记住这些参数,igel 会提示你输入这些内容。具体而言,Igel 会提供一条信息,解释你需要输入哪个参数。括号之间的值表示默认值。

端到端训练示例

项目作者给出了使用 igel 进行端到端训练的完整示例,即使用决策树算法预测某人是否患有糖尿病。你需要创建一个 yaml 配置文件,数据集可以在 examples 文件夹中找到。

拟合 / 训练模型:

model:type: classificationalgorithm: DecisionTreetarget:- sick
$ igel fit -dp path_to_the_dataset -yml path_to_the_yaml_file

现在,igel 将拟合你的模型,并将其保存在当前目录下的 model_results 文件夹中。

评估模型:

现在开始评估预训练模型。Igel 从 model_results 文件夹中加载预训练模型并进行评估。你只需要运行 evaluate 命令并提供评估数据的路径即可。

$ igel evaluate -dp path_to_the_evaluation_dataset

Igel 进行模型评估,并将 statistics/results 保存在 model_results 文件夹中的 evaluation.json 文件中。

预测:

这一步使用预训练模型预测新数据。这由 igel 自动完成,你只需提供预测数据的路径即可。

$ igel predict -dp path_to_the_new_dataset

Igel 使用预训练模型执行预测,并将其保存在 model_results 文件夹中的 predictions.csv 文件中。

高阶用法

你还可以通过在 yaml 文件中提供某些预处理方法或其他操作来执行它们。关于 yaml 配置文件请参考 GitHub 详细介绍。在下面的示例中,将数据拆分为训练集 80%,验证 / 测试集 20%。同样,数据在拆分时会被打乱。

此外,可以通过用均值替换缺失值来对数据进行预处理:

# dataset operations
dataset:split:test_size: 0.2shuffle: Truestratify: defaultpreprocess: # preprocessing optionsmissing_values: mean    # other possible values: [drop, median, most_frequent, constant] check the docs for moreencoding:type: oneHotEncoding  # other possible values: [labelEncoding]scale:  # scaling optionsmethod: standard    # standardization will scale values to have a 0 mean and 1 standard deviation  | you can also try minmaxtarget: inputs  # scale inputs. | other possible values: [outputs, all] # if you choose all then all values in the dataset will be scaled# model definition
model:type: classificationalgorithm: RandomForestarguments:# notice that this is the available args for the random forest model. check different available args for all supported models by running igel helpn_estimators: 100max_depth: 20# target you want to predict
target:- sick

然后,可以通过运行 igel 命令来拟合模型:

$ igel fit -dp path_to_the_dataset -yml path_to_the_yaml_file

评估:

$ igel evaluate -dp path_to_the_evaluation_dataset

预测:

$ igel predict -dp path_to_the_new_dataset

参考链接:https://medium.com/@nidhalbacc/machine-learning-without-writing-code-984b238dd890

© THE END

转载请联系 机器之心 公众号获得授权

投稿或寻求报道:content@jiqizhixin.com

一行代码不用写,就可以训练、测试、使用模型,这个star量1.5k的项目帮你做到...相关推荐

  1. 一行代码不用写,就可以训练、测试、使用模型,这个 star 量 1.5k 的项目帮你做到...

    公众号关注 "小詹学Python" 设为"星标",第一时间知晓最新干货~ 转自 | 机器之心 igel 是 GitHub 上的一个热门工具,基于 scikit- ...

  2. 在linux上一行代码不用写实现自动采集+hadoop分词

    在linux上一行代码不用写实现自动采集+hadoop分词 将下面的shell脚本保存成到xxx.sh,然后执行即可 cd /opt/hadoop mkdir spider wget -O spide ...

  3. Yolov5自定义图片训练测试及模型调优(详细过程)

    Yolov5自定义图片训练测试及模型调优(详细过程) 1. 图像数据获取.标注 2. 数据集划分及准备 3. 配置训练参数,准备训练: 3.1 修改data/训练配置xxx.yaml文件: 3.2 修 ...

  4. 不用写代码,就能训练测试深度学习模型!Uber开源AI工具箱Ludwig

    乾明 发自 凹非寺  量子位 报道 | 公众号 QbitAI 让代码的归代码,让AI的归AI. 在不写代码就能进行AI开发的道路上,Uber今日又往前踏了一步. 刚刚,Uber宣布开源Ludwig,一 ...

  5. 关于一行代码没写完换行\符号的注意

    通常我们在C\C++中一行代码写的很长需要换到下一行继续写,在行末加个'\'回车到下一行继续写, 如: printf("\nT%04dCH%02d%01d%04X%08X%04d%d%04d ...

  6. 一行代码,你就可以制作出放大镜软件

    首先,咱们打开这次编程需要用到的软件--Quick Batch File Compiler 然后,输入仅仅一行代码: magnify 点击"输出"重命名为"放大镜.exe ...

  7. ICML2020 | 一行代码就能实现的测试集上分技巧

    星标/置顶小屋,带你解锁 最萌最前沿的NLP.搜索与推荐技术 文 | 苏剑林 编 | 夕小瑶 在训练模型的时候,我们需要损失函数一直训练到0吗?显然不用.一般来说,我们是用训练集来训练模型,但希望的是 ...

  8. android文件添加一行代码怎么写,Android:以编程方式添加Textview,而不是将文本包装到下一行(示例代码)...

    我确定我做了一些愚蠢的错误,但这是我的问题. 基本上我尝试使用cardviews制作历史列表.在这些卡片视图中,我有一个垂直方向的LinearLayout,可以将我的所有内容都放入我的卡中. 在这个L ...

  9. 一行代码没写,凭啥被尊为“第一位程序员”?

    作者 | Aholiab 出品 | 程序人生 (ID:coder _life) 阿达·拉芙莱斯,一个 IT 圈里人人都听过的名字.被称为「程序员的开山鼻祖」,但也存在着旷日持久的争议. 探索关于 Ad ...

最新文章

  1. python强大体现在哪些方面-什么python的if语句?它主要应用在哪些方面?
  2. C# NPOCO 轻量级ORM框架(进阶)
  3. hdu 1576(拓展欧几里得)
  4. python之print实践
  5. 初学 Delphi 嵌入汇编[10] - 函数返回值与寄存器
  6. 怎么样实现对一个对象的深拷贝
  7. js动态加载HTML元素时出现的无效的点击事件
  8. 软件基本功能测试用例,测试用例实例—常见功能测试点().docx
  9. 三星 NAND 存储器新厂施工顺遂,上半年有望如期投产
  10. 简指南越狱的iOS及原因,负责其
  11. ubuntu使用双模机械师K7机械键盘遇到的问题
  12. 魅魔php影视系统,魅魔全新且强大的视频电影程序(MacCMS PHP) 6.1 20120511
  13. Python爬虫:js加密实例-有道翻译
  14. 数字的大写字母的乱序整理
  15. python爬虫和定位_Python网络爬虫实战,照片定位与B站弹幕!
  16. 与ERP有关的主要管理概念
  17. 万能SQL查询面试题
  18. Jenkin+GitLab自动构建Maven项目
  19. 根据卡号前6位判断开户银行
  20. win7 php搭建博客,win7下wordPress本地搭建博客详解(深度亲测整理—傻瓜式详细教程) | 学步园...

热门文章

  1. 【青少年编程】【一级】森林的一天
  2. 线性代数:04 特征值与特征向量 -- 特征值与特征向量
  3. 刻意练习:Python基础 -- Task11. 魔法方法
  4. adaptiveThreshold 阈值化的实现
  5. 【MATLAB】数组运算
  6. 快手日入数据量超 5120TB,数据管治如何做?
  7. 搞机器学习,Python和R哪个更合适?
  8. 【公开课预告】AutoML知多少
  9. Python数据清理终极指南(2020版)
  10. 知乎「致知计划之科学季」颁奖,创作者分享80万元奖金