一行代碼不用寫,就可以訓練、測試、使用模型,這個star量1.5k的...

2021-01-10 澎湃新聞

機器之心報導

機器之心編輯部

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 operationsdataset: type: csv # [str] -> type of your dataset read_data_options: # options you want to supply for reading your data (See the detailed overview about this in the next section) 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 use index_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 columns squeeze: # [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 columns engine: # [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 skip nrows: # [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 dates infer_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 operator decimal: # [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 quoting delim_whitespace: # [bool] -> Specifies whether or not whitespace (e.g. ' ' or ' ') will be used as the sep low_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 options test_size: 0.2 #[float] -> 0.2 means 20% for the test data, so 80% are automatically for training shuffle: true # [bool] -> whether to shuffle the data before/while splitting stratify: None # [list, None] -> If not None, data is split in a stratified fashion, using this as the class labels.

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

# model definitionmodel: 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 more arguments: # model arguments: you can check the available arguments for each model by running igel help in your terminal use_cv_estimator: false # [bool] -> if this is true, the CV class of the specific model will be used if it is supported cross_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 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 initpossible 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: [drop, median, most_frequent, constant] check the docs for more encoding: type: oneHotEncoding # other possible values: [labelEncoding] 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: [outputs, all] # 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

如何根據任務需求搭配恰當類型的資料庫?

在AWS推出的白皮書《進入專用資料庫時代》中,介紹了8種資料庫類型:關係、鍵值、文檔、內存中、關係圖、時間序列、分類帳、領域寬列,並逐一分析了每種類型的優勢、挑戰與主要使用案例。

原標題:《一行代碼不用寫,就可以訓練、測試、使用模型,這個star量1.5k的項目幫你做到》

閱讀原文

相關焦點

  • 一行代碼不用寫,就可以訓練、測試、使用模型,這個項目幫你做到
    用戶無需編寫一行代碼即可使用機器學習模型,只要有 yaml 或 json 文件,來描述你想做什麼即可。一行代碼不用寫,就可以訓練、測試和使用模型,還有這樣的好事?最近,軟體工程師 Nidhal Baccouri 就在 GitHub 上開源了一個這樣的機器學習工具——igel,並登上了 GitHub 熱榜。
  • 一行代碼調用預訓練模型,上海交大開源視頻理解工具箱AlphaVideo
    為了讓 h_s 和 h_t 各司其職,研究者將 h_s 和 h_t 設計為不對稱的結構,同時,使用兩個特殊的監督目標 r_s、r_t 來進一步約束二者關注各自的工作。該研究進一步提出了一種訓練注意力機制。這種注意力機制控制模型在優化過程中學習哪種信息。
  • 代碼也能預訓練,微軟&哈工大最新提出 CodeBERT 模型,支持自然...
    值一提的是,CodeBERT有一大亮點,即儘管它只在Ruby、JavaScript、Go、Python、Java、PHP等代碼語言上進行了預訓練,但預訓練的模型卻可以泛化到其他代碼語言任務上,例如C#語言。
  • AI輔助寫代碼,Python之父都愛不釋手的工具
    言歸正傳,這個工具是——這是一款IDE插件,使用機器學習為你的Python編程提供智能的代碼完成,從而加速你的編程速度。行了,既然提到」代碼完成「,各位肯定會想到IDE不都有這個功能嗎?這工具是不是有點多此一舉?
  • 1.8M超輕量目標檢測模型NanoDet,比YOLO快,上線兩天Star量超200
    這個項目對單階段檢測模型三大模塊(Head、Neck、Backbone)進行輕量化,得到模型大小僅 1.8m、速度超快的輕量級模型 NanoDet-m。目標檢測一直是計算機視覺領域的一大難題,其目標是找出圖像中的所有感興趣區域,並確定這些區域的位置和類別。目標檢測中的深度學習方法已經發展了很多年,並出現了不同類型的檢測方法。
  • Keras 之父講解 Keras:幾行代碼就能在分布式環境訓練模型 |...
    Francois Chollet:對許多使用場景而言,canned estimator 是相當不錯的選擇。但如果你要做的事並沒有現成的 canned estimator,怎麼辦?如果需要寫自己的定製模型呢?這時,就到了 Keras API 派上用場的時候。什麼是 Keras API?
  • 不用代碼,一分鐘體驗二十個開源模型
    Step1: 網頁地址 :https://ai.baidu.com/easyedge/home進入百度 EasyEdge 端計算模型生成平臺 Strp2: 點擊 「立即使用」進入操作中心後,選擇「體驗開源模型
  • KlipC使用Python模型和機器學習來計算貨幣(EUR / USD)未來走勢
    SVR生成的模型僅取決於訓練數據的子集,因為構建模型的成本函數會忽略任何接近模型預測的訓練數據。獲取數據集中的行和列,可以用來查看它們的計數,合計有30行6列數據。列印最後一行數據(這將是我們測試的數據)。請注意,日期是2018–01–31,所以日期是31。這將是預測開盤價為1.24131的模型輸入。
  • 人體模型介紹 - STAR
    項目主頁:https://star.is.tue.mpg.de項目代碼:https://github.com/ahmedosman/STAR為了進一步增加模型的緊緻性,作者使用四元數來表達每個關節點角度,這樣每個關節點只有 4 個姿態矯正回歸項,相比 SMPL 使用旋轉矩陣的 9 個元素大大減少了參數量,但性能並沒有下降。
  • 無性能損失,不用更改代碼,Lightning 1.1版本發布
    新版本新增了 sharded training 功能,在多 GPU 上訓練深度學習(DL)模型時可以節省 50% 以上的內存,並且沒有性能損失,也不需要更改代碼。在不更改代碼的情況下啟用 Sharded Training為了展示在 Lightning 中使用 Sharded Training 有多簡單,使用 NVIDIA 的一個流行庫 NeMo 來訓練 Lightning 支持的對話 AI 模型。
  • 幾行代碼搞定ML模型,低代碼機器學習Python庫正式開源
    想提高機器學習實驗的效率,把更多精力放在解決業務問題而不是寫代碼上?低代碼平臺或許是個不錯的選擇。最近,機器之心發現了一個開源低代碼機器學習 Python 庫 PyCaret,它支持在「低代碼」環境中訓練和部署有監督以及無監督的機器學習模型。
  • 驚為天人,NumPy手寫全部主流機器學習模型,代碼超3萬行
    它為 Python 提供高效率的多維數組計算,並提供了一系列高等數學函數,我們可以快速搭建模型的整個計算流程。毫不負責任地說,NumPy 就是現代深度學習框架的「爸爸」。儘管目前使用 NumPy寫模型已經不是主流,但這種方式依然不失為是理解底層架構和深度學習原理的好方法。
  • 一行代碼安裝,TPU也能運行PyTorch,修改少量代碼即可快速移植
    現在福利來了,一個叫做Pytorch Lightning的項目,可以讓你幾乎修改代碼的情況下用上TPU。Pytorch Lightning已經上傳到PyPI,因此只需一行代碼就能安裝這個軟體。使用方法PyTorch Lightning具體該如何使用,作者Falcon還是以MNIST圖像分類網絡為例,介紹從收集數據到訓練再到驗證、測試的全過程。準備數據集階段分為下載圖片、轉換、分割數據集、打包四個步驟。
  • 使用Amazon SageMaker 構建基於 gluon 的推薦系統
    本解決方案使用 Amazon SageMaker,它可以幫助開發人員和數據科學家構建、訓練和部署 ML 模型。Amazon SageMaker 是一項完全託管的服務,涵蓋了 ML 的整個工作流,可以標記和準備數據、選擇算法、訓練模型、調整和優化模型以便部署、預測和執行操作。
  • Unity Perception工具 | 使用合成數據訓練出強大的物體檢測ML模型
    其中760張圖像被用作訓練,253張圖像被用作驗證,餘下的254張圖像被用於測試,任何使用現實圖像訓練的模型都會用到這三組數據。使用驗證組是為了選出性能最好的模型、防止出現過擬合。而保留組(剩下的測試圖像)從未被模型觀察過,也從未暗中或明著使用數據來選取模型或設定模型超參數。
  • 使用Python和Numpy構建神經網絡模型——波士頓房價預測案例
    #在本項目中,為了便於理解,可以簡化直接整除14就好了#data = data.reshape([7084// 14, 14])2.1.3 數據集劃分將數據集劃分成訓練集和測試集,其中訓練集用於確定模型的參數,測試集用於評判模型的效果。
  • Facebook 100種語言互譯模型原始碼公開!機器翻譯再也不用英語當...
    智東西(公眾號:zhidxcom)編 | 子佩智東西10月23日消息,Facebook近期開源其M2M-100原始碼,這是首個可以不依賴英語數據而可以實現100個語言對互相翻譯的機器翻譯模型(如中文-法文互譯為一個語言對)。
  • 深度學習-Pytorch框架學習之模型訓練和測試
    前言前面四篇文章,介紹了模型搭建、數據準備及pytorch中常用的計算方法等,有了上述基礎後就可以訓練模型了,下面這篇文章會簡單介紹下在pytorch框架下如何訓練深度學習模型,以及一些常用代碼。模型訓練
  • 使用單行代碼評估回歸模型的Python包
    對此的一個內聯嘗試是python包「 regressormetricgraphplot」的開發,該軟體包旨在幫助用戶使用單行代碼繪製評估指標圖,以針對不同的廣泛使用的回歸模型指標進行一目了然的比較。使用該實用程序包,還可以通過將其應用於日常的預測回歸問題,顯著降低從業人員以業餘方式評估不同機器學習算法的障礙。
  • 使用YApi 管理 API 文檔、測試、MOCK
    如下圖所示,按以往的做法,接口文檔管理因為沒有跟開發和測試整合到一起被孤立,導致後端維護對於他們冗雜繁瑣的文檔,是件收益很低的事情。沒有人喜歡做收益低的事情,只有提高了維護接口文檔的收益,才能真正解決這個問題。 在接口開發過程中,後端通常都會使用 postman 等類似的工具測試接口,而測試接口是在開發過程中一個必要的過程。