糖藥病數據集分類_使用optuna和mlflow進行心臟病分類器調整

糖藥病數據集分類

背景 (Background)

Data science should be an enjoyable process focused on delivering insights and real benefits. However, that enjoyment can sometimes get lost in tools and processes. Nowadays it is important for an applied data scientist to be comfortable using tools and software for data/code versioning, reproducible model development, experiment tracking, and model inspection — to name a few!

數據科學應該是一個令人愉悅的過程,專注于提供見解和實際收益。 但是,這種享受有時會在工具和過程中迷失。 如今,重要的是,對于應用數據科學家來說,使用工具和軟件進行數據/代碼版本控制,可重現的模型開發,實驗跟蹤和模型檢查非常重要!

The purpose of this article is to briefly touch upon reproducible model development and experiment tracking through a worked example for tuning a Random Forest classifier using Optuna and mlflow.

本文的目的是通過一個使用Optuna和mlflow調整隨機森林分類器的實例簡要討論可再現模型的開發和實驗跟蹤。

心臟病數據和預處理 (The heart disease data and preprocessing)

This example uses the heart disease data available in the UCI ML archive. In previous work I describe some processing done to create a semi-cleaned dataset: developing a model for heart disease prediction using pycaret. In the .csv file provided for this short worked example, I have additionally converted any categorical features with two values into a single binary feature where for feature_name_x the _x suffix indicates the level represented by a value of 1. The target to predict is heart disease (hd_yes) and we want to tune a Random Forest classifier to do so.

本示例使用UCI ML存檔中可用的心臟病數據。 在之前的工作中,我描述了創建半清潔數據集的一些處理過程: 使用pycaret開發用于心臟病預測的模型 。 在為該簡短示例提供的.csv文件中,我另外將具有兩個值的所有分類特征轉換為單個二進制特征,其中對于feature_name_x_x后綴表示值1表示的水平。要預測的目標是心臟病( hd_yes ),我們想調整隨機森林分類器。

After loading the data and creating the feature matrix and target vector, I created a preprocessing pipeline. For numeric features missing values were imputed using the median and then scaled. For binary features missing values were imputed using the mode. For a three-level categorical feature chest pain, missing values were treated as a separate category and leave-one-out target encoding applied. Finally, these processing steps were wrapped up into a single processing pipeline.

加載數據并創建特征矩陣和目標矢量后,我創建了預處理管道。 對于數字特征,使用中位數估算缺失值,然后進行縮放。 對于二進制特征,使用該模式估算缺失值。 對于三級分類的特征性胸痛,缺失值被視為一個單獨的類別,并應用了遺忘的目標編碼 。 最后,這些處理步驟被包裝到單個處理管道中。

使用Optuna和mlflow (Using Optuna and mlflow)

With our feature matrix, target vector and preprocessing pipeline ready to go, we can now tune a Random Forest classifier to predict heart disease. Note for the purpose of this demonstration I am going to forgo the use of a hold-out test set. To do the hyper-parameter optimization (model development) we will use Optuna and for experiment tracking one of its newer features: mlflow integration (see: mlflow callback in Optuna and mlflow tracking).

利用我們的特征矩陣,目標向量 并準備好進行預處理,我們現在可以調整“隨機森林”分類器來預測心臟病。 請注意,出于演示目的,我將放棄使用保持測試集。 為了進行超參數優化(模型開發),我們將使用Optuna并進行實驗跟蹤,以實現其較新的功能之一 :mlflow集成(請參閱: Optuna中的mlflow回調和mlflow跟蹤 )。

First, we begin by defining the objective function to optimize with Optuna (Figure 1), which has three main components:

首先,我們首先定義目標函數以使用Optuna進行優化( 圖1 ),它具有三個主要組件:

  1. Defining the space of hyper-parameters and values to optimize: in our case we focus on six Random Forest hyper-parameters (n_estimators, max_depth, max_features, bootstrap, min_samples_split, min_samples_split)

    定義要優化的超參數和值的空間 :在本例中,我們集中于六個隨機森林超參數(n_estimators,max_depth,max_features,bootstrap,min_samples_split,min_samples_split)

  2. The Machine Learning pipeline: we have a preprocessing pipeline plus a Random Forest classifier

    機器學習管道 :我們有一個預處理管道以及一個隨機森林分類器

  3. The calculation of the metric to optimize: we use the 5-fold CV average ROC AUC

    優化指標的計算 :我們使用5倍CV平均ROC AUC

Figure 1. The Optuna objective function圖1. Optuna目標函數

Next, we define a callback to mlflow, one of the new (and experimental!) features in Optuna 2.0 in order to track our classifier hyper-parameter tuning (Figure 2).

接下來,我們定義對mlflow的回調,這是Optuna 2.0中的新功能(也是實驗性功能!)之一,以便跟蹤分類器的超參數調整( 圖2 )。

Figure 2. Setting the mlflow callback to track an Optuna study圖2.設置mlflow回調以跟蹤Optuna研究

Then we instantiate the Optuna study object to maximize our chosen metric (ROC AUC) (Figure 3). We also apply Hyperband pruning, which helps find optimums in shorter times by stopping unpromising trials early. Note that this is typically of more benefit for more intensive and difficult optimization such as in deep learning.

然后,我們實例化Optuna研究對象以最大化我們選擇的指標(ROC AUC)( 圖3 )。 我們還應用了Hyperband修剪 ,可通過盡早停止毫無希望的試驗來幫助您在更短的時間內找到最佳選擇。 請注意,這通常對于深度學習等更深入,更困難的優化更有利。

Figure 3. Creating an Optuna study圖3 。 創建一個Optuna研究

Finally, we run the hyper-parameter tuning using 200 trials (Figure 4). It may take a couple of minutes to run.

最后,我們使用200次試驗運行超參數調整( 圖4 )。 運行可能需要幾分鐘。

Figure 4. Running the hyper-parameter optimization using Optuna圖4.使用Optuna運行超參數優化

The mlflow logged experiment including assessed hyper-parameter configurations for the Random Forest classifier (Optuna study/trials), are stored in a folder called mlruns. To view these results using the mlflow user interface, do the following:

mlflow記錄的實驗(包括為隨機森林分類器評估的超參數配置(Optuna研究/試驗))存儲在名為mlruns的文件夾中。 要使用mlflow用戶界面查看這些結果,請執行以下操作:

  1. Open a shell (for example a Windows PowerShell) in the directory containing the mlruns folder

    在包含mlruns文件夾的目錄中打開外殼程序(例如Windows PowerShell)
  2. Activate the virtual environment used for this notebook, i.e., conda activate optuna_env

    激活用于此筆記本的虛擬環境,即conda activate optuna_env

  3. Run mlflow ui

    運行mlflow ui

  4. Navigate to the localhost address provided, something like: http://kubernetes.docker.internal:5000/

    導航到提供的localhost地址,例如: http://kubernetes.docker.internal:5000/

You should see Figure 5, and you can sift through the experiment trials. I deselected the user, source and version columns, as well as the tags section to simplify the view. I also sorted the results by ROC AUC. The top hyper-parameter configurations provided a ROC AUC of 0.917, where max_depth was in the range 14 to 16, max_features was 4, min_samples_leaf was 0.1, min_samples_split was 0.2, and n_estimators was 340 (note these results may differ slightly for you if you re-run the notebook).

您應該看到圖5 ,然后可以篩選實驗。 我取消選擇了用戶,源和版本列以及標簽部分,以簡化視圖。 我還按ROC AUC對結果進行了排序。 頂級超參數配置的ROC AUC為0.917,其中max_depth在14到16之間,max_features是4,min_samples_leaf是0.1,min_samples_split是0.2,n_estimators是340(請注意,如果您使用重新運行筆記本)。

Image for post
Figure 5. mlflow summary for Optuna HPO of our heart disease random Forest classifier圖5.我們的心臟病隨機森林分類器的Optuna HPO的mlflow摘要

Optuna also has great visualizations for summarizing experiments. Here we look at hyper-parameter importance and the optimization history (Figure 6). We can see that the min_samples_leaf is the most important hyper-parameter to tune in this example. The hyper-parameter importance is calculated using a functional ANOVA approach. For more information see Hutter, Hoos and Leyton-Brown 2014.

Optuna還具有用于匯總實驗的出色可視化效果。 在這里,我們看一下超參數的重要性和優化歷史( 圖6 )。 我們可以看到,在此示例中,min_samples_leaf是最重要的超參數。 使用功能方差分析方法計算超參數重要性。 有關更多信息,請參閱Hutter,Hoos和Leyton-Brown 2014 。

Image for post
Figure 6. Hyper-parameter importance (left) and the optimization history for ROC AUC (right)圖6.超參數重要性(左)和ROC AUC的優化歷史(右)

摘要 (Summary)

Optuna has come a long way since its inception and version 2.0 released in July this year has some fantastic additions, one of which we touched upon in this short article: the mlflow callback. Perhaps as expected the tuning worked great and the summaries available via the in-built visualizations in Optuna and using the mlflow UI made this a lot of fun.

Optuna自問世以來已經走了很長一段路,并且在今年7月發布的2.0版中添加了一些很棒的功能,我們在這篇短文中談到了其中之一:mlflow回調。 也許正如預期的那樣,調整效果很好,并且通過Optuna的內置可視化工具以及使用mlflow UI的摘要提供了很多樂趣。

The jupyter notebook, virtual environment and data used for this article are available at my GitHub. As always comments, thoughts, feedback and discussion are very welcome.

我的GitHub上提供了本文使用的jupyter筆記本,虛擬環境和數據。 與往常一樣,我們非常歡迎評論,想法,反饋和討論。

翻譯自: https://medium.com/@jasonpben/heart-disease-classifier-tuning-using-optuna-and-mlflow-fc1366eefdec

糖藥病數據集分類

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/389509.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/389509.shtml
英文地址,請注明出處:http://en.pswp.cn/news/389509.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Android MVP 框架

為什么80%的碼農都做不了架構師?>>> 前言 根據網絡上的MVP套路寫了一個辣雞MVP DEMO 用到的 android studio MVPHelper插件,方便自動生成框架代碼rxjavaretrofit什么是MVP MVP就是英文的Model View Presenter,然而實際分包并不是只有這三個包…

相似圖像搜索的哈希算法思想及實現(差值哈希算法和均值哈希算法)

圖像相似度比較哈希算法: 什么是哈希(Hash)? ? 散列函數(或散列算法,又稱哈希函數,英語:Hash Function)是一種從任何一種數據中創建小 的數字“指紋”的方法。散列函數把消息或數…

騰訊云AI應用產品總監王磊:AI 在傳統產業的最佳實踐

歡迎大家前往騰訊云社區,獲取更多騰訊海量技術實踐干貨哦~ 背景:5月23-24日,以“煥啟”為主題的騰訊“云未來”峰會在廣州召開,廣東省各級政府機構領導、海內外業內學術專家、行業大咖及技術大牛等在現場共議云計算與數字化產業創…

標準化(Normalization)和歸一化實現

概念: 原因: 由于進行分類器或模型的建立與訓練時,輸入的數據范圍可能比較大,同時樣本中各數據可 能量綱不一致,這樣的數據容易對模型訓練或分類器的構建結果產生影響,因此需要對其進行標準 化處理&#x…

Toast源碼深度分析

目錄介紹 1.最簡單的創建方法 1.1 Toast構造方法1.2 最簡單的創建1.3 簡單改造避免重復創建1.4 為何會出現內存泄漏1.5 吐司是系統級別的 2.源碼分析 2.1 Toast(Context context)構造方法源碼分析2.2 show()方法源碼分析2.3 mParams.token windowToken是干什么用的2.4 schedul…

序列化框架MJExtension詳解 + iOS ORM框架

當開發中你的模型中屬性名稱和 字典(JSON/XML) 中的key 不能一一對應時, 或者當字典中嵌套了多層字典數組時..., 以及教你如何用 MJExtension 配置類來統一管理你的模型配置, 下面羅列了開發中常見的一些特殊情況, 請參考!(MJExtension/github) 最基本用法: // 將字典轉為模型 …

運行keras出現 FutureWarning: Passing (type, 1) or ‘1type‘ as a synonym of type is deprecated解決辦法

運行keras出現 FutureWarning: Passing (type, 1) or ‘1type’ as a synonym of type is deprecated; in a future version of numpy, 原則來說,沒啥影響,還是能運行,但是看著難受 解決辦法: 點擊藍色的鏈接: 進入 …

RedirectToAction()轉移方式及參數傳遞

今天在做一個功能的時,使用RedirectToAction()需要從這里傳幾個參數,從網上查了一下,這樣解決。真好。 Return RedirectToAction("Index","ManageInfo",new{type0,page1});轉載于:https://www.cnblogs.com/ZaraNet/p/978…

軟件項目風險管理

近幾年來軟件開發技術、工具都有了很大的進步,但是軟件項目開發超時、超支、甚至不能滿足用戶需求而根本沒有得到實際使用的情況仍然比比皆是。軟件項目開發和管理中一直存在著種種不確定性,嚴重影響著項目的順利完成和提交。但這些軟件風險并未得到充分…

mongdb 群集_群集文檔的文本摘要

mongdb 群集This is a part 2 of the series analyzing healthcare chart notes using Natural Language Processing (NLP)這是使用自然語言處理(NLP)分析醫療保健圖表筆記的系列文章的第2部分。 In the first part, we talked about cleaning the text and extracting sectio…

keras框架實現手寫數字識別

詳細細節可學習從零開始神經網絡:keras框架實現數字圖像識別詳解! 代碼實現: [1]將訓練數據和檢測數據加載到內存中(第一次運行需要下載數據,會比較慢): (mnist是手寫數據集) train_images是用于訓練系統…

gdal進行遙感影像讀寫_如何使用遙感影像進行礦物勘探

gdal進行遙感影像讀寫Meet Jose Manuel Lattus, a geologist from Chile. In the latest Soar Cast, he discusses his work in mineral exploration and environmental studies, and explains how he makes a living by creating valuable information products based on diff…

從零開始神經網絡:keras框架實現數字圖像識別詳解!

接口實現可參考:keras框架實現手寫數字識別 思路: 我們的代碼要導出三個接口,分別完成以下功能: 初始化initialisation,設置輸入層,中間層,和輸出層的節點數。訓練train:根據訓練數據不斷的更…

大數據學習第一貼

搞了這么久的開發,一直沒有養成發博客的習慣,今天開始對大數據所需內容進行總結性記錄,并對以后遇到的問題形成一個自己的知識庫。就這些!轉載于:https://blog.51cto.com/13921538/2299765

推薦算法的先驗算法的連接_數據挖掘專注于先驗算法

推薦算法的先驗算法的連接So here we are diving into the world of data mining this time, let’s begin with a small but informative definition;因此,這一次我們將進入數據挖掘的世界,讓我們從一個小的但內容豐富的定義開始; 什么是數…

Android 頁面多狀態布局管理

一、現狀 頁面多狀態布局是開發中常見的需求,即頁面在不同狀態需要顯示不同的布局,實現的方式也比較多,最簡單粗暴的方式就是在 XML 中先將不同狀態對應的布局隱藏起來,根據需要改變其可見狀態,如果多個界面公用相同的…

Tensorflow入門神經網絡代碼框架

Tensorflow—基本用法 使用圖 (graph) 來表示計算任務.在被稱之為 會話 (Session) 的上下文 (context) 中執行圖.使用 tensor 表示數據.通過 變量 (Variable) 維護狀態.使用 feed 和 fetch 可以為任意的操作(arbitrary operation)賦值或者從其中獲取數據。 ? TensorFlow 是一…

手把手教你把代碼丟入github 中

手把手教你把代碼丟入github 中 作為一個小運維一步步教你們怎么把代碼放入到github 中 首先呢我們下載一個git的客戶端 https://git-scm.com/downloads/ 下載一個最新版的2.16.2 下載后那就安裝吧。如果看不懂英文就選擇默認安裝的方式吧。但是你得記住你的軟件安裝的位置 小…

時間序列模式識別_空氣質量傳感器數據的時間序列模式識別

時間序列模式識別 1. Introduction 2. Exploratory Data Analysis ° 2.1 Pattern Changes ° 2.2 Correlation Between Features 3. Anomaly Detection and Pattern Recognition ° 3.1 Point Anomaly Detection (System Fault) ° 3.2 Collective Anomaly Detection (Externa…

oracle 性能優化 07_診斷事件

2019獨角獸企業重金招聘Python工程師標準>>> 一、診斷事件 診斷事件無官方技術文檔支持,使用存在風險,慎用。使用診斷事件可以獲取問題更多的信息,調整系統運行 特性,啟用某些內部功能。用于系統故障的診斷。跟蹤應…