optional,options翻译成中文

  

  机器心脏报告   

  

  机器之心编辑部   

  

  Igel是GitHub上比较流行的工具,基于scikit-learn构建,支持sklearn的所有机器学习功能,比如回归、分类、聚类等。用户不用写一行代码就可以使用机器学习模型,只要有yaml或者json文件来描述你想做的事情。   

  

     

  

  您可以训练、测试和使用模型,而无需编写任何代码。有这种好事吗?   

  

  最近,软件工程师Nidhal Baccouri在GitHub上开辟了这样一个机器学习工具——IGEL,并登上了GitHub的热门榜单。目前这个项目的星量已经达到了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 #-您要为读取数据提供的数据集类型read_data_options: #选项(请参见下一节中关于此的详细概述)sep: # -要使用的分隔符。分隔符: # -sep . header的别名: #-用作列名的行号,以及数据的开头。names: # -要使用的列名列表index_col: # -要用作数据帧的行标签的列,usecols: # -返回列的子集squeeze: # -如果解析的数据只包含一列,则返回一系列。prefix: # -当没有标题时添加到列号的前缀,例如' X '表示X0,X1,… mangle_dupe_cols: # -重复的列将被指定为' X ',' X.1 ',…'X.N ',而不是' X'…'X '。如果列中有重复的名称,传入False将导致数据被覆盖。dtype: # -数据或列引擎的数据类型。C引擎速度更快,而python引擎目前功能更完善。这个函数的字典用于转换某些列中的值。键可以是整数,也可以是列标签。true_values: #   

ist> -> Values to consider as True. false_values: # -> Values to consider as False. skipinitialspace: # -> Skip spaces after delimiter. skiprows: # -> Line numbers to skip (0-indexed) or number of lines to skip (int) at the start of the file. skipfooter: # -> Number of lines at bottom of file to skip nrows: # -> Number of rows of file to read. Useful for reading pieces of large files. na_values: # -> Additional strings to recognize as NA/NaN. keep_default_na: # -> Whether or not to include the default NaN values when parsing the data. na_filter: # -> 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: # -> Indicate number of NA values placed in non-numeric columns. skip_blank_lines: # -> If True, skip over blank lines rather than interpreting as NaN values. parse_dates: # -> try parsing the dates infer_datetime_format: # -> 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: # -> If True and parse_dates specifies combining multiple columns then keep the original columns. dayfirst: # -> DD/MM format dates, international and European format. cache_dates: # -> If True, use a cache of unique, converted dates to apply the datetime conversion. thousands: # -> the thousands operator decimal: # -> Character to recognize as decimal point (e.g. use ‘,’ for European data). lineterminator: # -> Character to break file into lines. escapechar: # -> One-character string used to escape other characters. comment: # -> 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: # -> Encoding to use for UTF when reading/writing (ex. ‘utf-8’). dialect: # -> If provided, this parameter will override values (default or not) for the following parameters: delimiter, doublequote, escapechar, skipinitialspace, quotechar, and quoting delim_whitespace: # -> Specifies whether or not whitespace (e.g. ' ' or ' ') will be used as the sep low_memory: # -> Internally process the file in chunks, resulting in lower memory use while parsing, but possibly mixed type inference. memory_map: # -> 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 options test_size: 0.2 # -> 0.2 means 20% for the test data, so 80% are automatically for training shuffle: true # -> whether to shuffle the data before/while splitting stratify: None # -> If not None, data is split in a stratified fashion, using this as the class labels.

  

preprocess: # preprocessing options missing_values: mean # -> other possible values: check the docs for more encoding: type: oneHotEncoding # -> other possible values: scale: # scaling options method: standard # -> standardization will scale values to have a 0 mean and 1 standard deviation | you can also try minmax target: inputs # -> scale inputs. | other possible values: # if you choose all then all values in the dataset will be scaled

  

# model definitionmodel: type: classification # -> type of the problem you want to solve. | possible values: algorithm: NeuralNetwork # -> which algorithm you want to use. | type igel algorithms in the Terminal to know more arguments: # model arguments: you can check the available arguments for each model by running igel help in your terminal use_cv_estimator: false # -> if this is true, the CV class of the specific model will be used if it is supported cross_validate: cv: # -> number of kfold (default 5) n_jobs: # -> The number of CPUs to use to do the computation (default None) verbose: # -> The verbosity level. (default 0)

  

# target you want to predicttarget: # 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 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: classification algorithm: DecisionTree

  

target: - 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 operationsdataset: split: test_size: 0.2 shuffle: True stratify: default

  

preprocess: # preprocessing options missing_values: mean # other possible values: check the docs for more encoding: type: oneHotEncoding # other possible values: scale: # scaling options method: standard # standardization will scale values to have a 0 mean and 1 standard deviation | you can also try minmax target: inputs # scale inputs. | other possible values: # if you choose all then all values in the dataset will be scaled

  

# model definitionmodel: type: classification algorithm: RandomForest arguments: # notice that this is the available args for the random forest model. check different available args for all supported models by running igel help n_estimators: 100 max_depth: 20

  

# target you want to predicttarget: - 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

相关文章