自動化機器學習指南之四大成熟度模型
譯文【51CTO.com快譯】人工智能和機器學習的概念在數據科學界中已經普遍流行。通過這些概念,過去許多需要人工完成的任務,已經能夠被更加高效且準確的自動化方式所取代。可以說,隨著技術趨勢的變化,自動化機器學習在簡化人工操作的基礎上,既節省了時間又提高了效率。
自動化機器學習:自動化訓練過程
從概念上說,機器學習旨在通過對機器進行訓練,通過處理現實數據的方式,提供預期的輸出。也就是說:它能夠讓機器從現有的數據(或經驗)中得到一定程度的訓練,在經歷了一番完整的數據處理之后,進而生成更準確的輸出。那么自動化機器學習(AutoML)的概念顯然是要使得整個過程徹底實現自動化。
自動化機器學習的成熟度模型
自動化機器學習的不同實現方式可以根據它們所對應的成熟度,進行不同級別的分類。如下圖所示,模型成熟度越高,表示它對于自動化任務的支持就越好,當然也就需要該模型能夠通過對于數據的集中訓練,執行更多的任務、提供更多的服務。
1.超參數優化
當數據集被提交過來之后,自動化機器學習會根據上述成熟度模型,嘗試著去匹配各種既有的模型,例如:隨機森林、線性回歸等(一般使用的是結構化的數據)。同時,它會按需為那些應用到數據上的每一種模型,去優化超參數(hyperparamters)。此類優化技術包括:手動搜索、隨機搜索、網格搜索等。
例如:Auto-sklearn使用貝葉斯模型進行超參數優化,并且能夠提供所需的結果。不過,在該級別的成熟度模型中,自動化機器學習只能執行有限的任務,例如:交叉驗證、機器學習算法的選擇、超參數的優化等。當然,隨著成熟度水平的提高,自動化機器學習將會具有更多的功能,提供更出色的結果。
2. 一級以上的數據預處理
在第一級中,自動化機器學習需要用戶自行實現數據的預處理措施。但是,到了第二級,由于使用了更為成熟的模型,各種數據的預處理任務便可以由自動化本身來完成,并為進一步處理做好準備。
通過搜索和了解列的類型,機器學習自身完全有能力將所有數據(包括一些空值數據)轉換為常見的數值類型。當然,此處并不包括對于數據的高級轉換與預處理,這些仍然需要數據科學家自行采取進一步的操作。
對于目標任務而言,系統僅負責搜索和選擇適當的機器學習算法。例如:根據手頭的移動應用開發任務,設計自動化機器學習的算法與模型,通過對于數據的預處理,以得出所需的預算、時間、以及其他準確的結果。
通過對于數據的預處理,自動化機器學習系統能夠構建并實現特征選擇、降低維度、數據壓縮等功能,進而無縫地執行各項訓練任務。
3.找到合適的機器學習架構
上述第一、二級自動化機器學習系統,顯然無法根據數據的性質,主動發現合適的機器學習架構,并通過執行,以確保出色的輸出。而在第三級中,以AutoKeras為代表的開源式自動化機器學習庫,實現了神經架構搜索(NAS,neural architecture search,請參見:https://en.wikipedia.org/wiki/Neural_architecture_search)。該流行架構能夠有效地在圖像、語音或文本上實施機器學習算法。
因此,數據科學家可以使用不同的神經架構搜索算法,來增強對于自動化機器學習的支持與經驗積累。在實際應用中,自動駕駛汽車、自動化消費服務等領域都采用了第三級的自動化機器學習系統。
4.相關領域知識的使用
為了能夠提供準確的機器學習系統輸出,深入地了解數據,特別是數據的范圍和承載的系統是非常必要的。只有使用相關領域的知識,并時刻參照所有必需考慮的標準,才能實現復雜的人工智能的效果。
可見,針對現有相關領域的知識儲備和在實際場景中的使用,無疑會提高最終結果的準確性。與此同時,準確性的提高也會驅動出色的預測能力,并為自動化機器學習的各項任務提供全面的支持。因此,這個級別的成熟度模型注重的是:通過增加背景領域的相關知識,憑借具有明確結果導向(result-oriented)的記錄,來提高自動化機器學習系統的準確性。
自動化機器學習的實例
從事數據科學研究的人員可以根據實際應用場景的需求,使用各種工具和軟件庫來開發自動化的流程、以及具有精準輸出的機器學習系統。
自動化機器學習的開源庫
目前,業界有著很多種類的開源庫,能夠支持和滿足開發人員在其系統中實現各種自動化的機器學習需求。
1. AutoKeras
該軟件庫在GitHub上可供開發人員免費使用。由Data Lab開發的AutoKeras,旨在提供對于所有深度學習(deep learning)工具的訪問,進而增強深度學習模型的整體能力。如下代碼是AutoKeras的應用示例:
- import autokeras as ak
- clf = ak.ImageClassifier()
- clf.fit(x_train, y_train)
- results = clf.predict(x_test)
Python源代碼鏈接:https://github.com/jhfjhfj1/autokeras
2. MLBox
MLBox是另一種使用Python編寫的開源庫。它能夠更快、更輕松地開發出自動化機器學習的各種函數,其中包含了可用于數據預處理、清理、以及格式化等功能。如下代碼示例展示了在導入數據之后,如何進行數據預處理的過程:
- from mlbox.preprocessing import *
- from mlbox.optimisation import *
- from mlbox.prediction import *
- paths = ["../input/train.csv","../input/test.csv"]
- target_name = "Survived"
- rd = Reader(sep = ",")
- df = rd.train_test_split(paths, target_name) #reading and preprocessing (dates, ...)
Python源代碼鏈接:https://www.kaggle.com/axelderomblay/running-mlbox-auto-ml-package-on-titanic
3. Auto-sklearn
Auto-sklearn是另一種開源的自動化機器學習支持庫。它通過選擇適當的機器學習算法,來研究數據的模型和需求。它消除了用戶端對于超參數處理的要求,進而能夠自行開展處理工作。如下代碼是在數據集上實現Auto-sklearn的應用示例:
- import autosklearn.classification
- import sklearn.model_selection
- import sklearn.datasets
- import sklearn.metrics
- X, y = sklearn.datasets.load_digits(return_X_y=True)
- X_train, X_test, y_train, y_test = \
- sklearn.model_selection.train_test_split(X, y, random_state=1)
- automl = autosklearn.classification.AutoSklearnClassifier()
- automl.fit(X_train, y_train)
- y_hat = automl.predict(X_test)
- print("Accuracy score", sklearn.metrics.accuracy_score(y_test, y_h
Python源代碼鏈接:https://自動化機器學習.github.io/auto-sklearn/master/
自動化機器學習工具
如下工具雖然是為商業用途而發布的,但是它們不但得到了廣泛地使用,而且保證了自動化機器學習的輸出質量。
DataRobot
DataRobot是第一款支持自動化機器學習的工具。它提供了一個能夠實現人工智能的先進平臺,在協助用戶解決各項問題的同時,用戶可以不必過于擔心其執行過程,而能夠輕松地獲取所需的結果。DataRobot API不但支持預測,而且能夠使機器通過選擇適當的方法,來實現自動化處理,并提供輸出結果。
如下代碼是DataRobot API的一個應用示例。它使用數據集來預測30天之內各家醫院的患者可能再次入院的幾率。
- import datarobot as dr
- import pandas as pd
- pd.options.display.max_columns = 1000
- import numpy as np
- import time
- import matplotlib.pyplot as plt
- from jupyterthemes import jtplot
- # currently installed theme will be used to set plot style if no arguments provided
- jtplot.style()
- get_ipython().magic('matplotlib inline')
- # load input data
- df = pd.read_csv('../demo_data/10kDiabetes.csv')
- # initialize datarobot client instance
- dr.Client(config_path='/Users/benjamin.miller/.config/datarobot/my_drconfig.yaml')
- # create 100 samples with replacement from the original 10K diabetes dataset
- samples = []
- for i in range(100):
- samples.append(df.sample(10000, replace=True))
- # loop through each sample dataframe
- for i, s in enumerate(samples):
- # initialize project
- project = dr.Project.start
- (
- project_name='API_Test_{}'.format(i+20),
- sourcedata=s,
- target='readmitted',
- worker_count=2
- )
- # get all projects
- projects = []
- for project in dr.Project.list():
- if "API_Test" in project.project_name:
- projects.append(project)
- # *For each project...*
- # Make predictions on the original dataset using the most accurate model
- # initialize list of all predictions for consolidating results
- bootstrap_predictions = []
- # loop through each relevant project to get predictions on original input dataset
- for project in projects:
- # get best performing model
- model = dr.Model.get(project=project.id, model_id=project.get_models()[0].id)
- # upload dataset
- new_data = project.upload_dataset(df)
- # start a predict job
- predict_job = model.request_predictions(new_data.id)
- # get job status every 5 seconds and move on once 'inprogress'
- for i in range(100):
- time.sleep(5)
- try:
- job_status = dr.PredictJob.get(
- project_id=project.id,
- predict_job_id=predict_job.id
- ).status
- except: # normally the job_status would produce an error when it is completed
- break
- # now the predictions are finished
- predictions = dr.PredictJob.get_predictions(
- project_id=project.id,
- predict_job_id=predict_job.id
- )
- # extract row ids and positive probabilities for all records and set to dictionary
- pred_dict = {k: v for k, v in zip(predictions.row_id, predictions.positive_probability)}
- # append prediction dictionary to bootstrap predictions
- bootstrap_predictions.append(pred_dict)
- # combine all predictions into single dataframe with keys as ids
- # each record is a row, each column is a set of predictions pertaining to
- # a model created from a bootstrapped dataset
- df_predictions = pd.DataFrame(bootstrap_predictions).T
- # add mean predictions for each observation in df_predictions
- df_predictions['mean'] = df_predictions.mean(axis=1)
- # place each record into equal sized probability groups using the mean
- df_predictions['probability_group'] = pd.qcut(df_predictions['mean'], 10)
- # aggregate all predictions for each probability group
- d = {} # dictionary to contain {Interval(probability_group): array([predictions])}
- for pg in set(df_predictions.probability_group):
- # combine all predictions for a given group
- frame = df_predictions[df_predictions.probability_group == pg].iloc[:, 0:100]
- d[str(pg)] = frame.as_matrix().flatten()
- # create dataframe from all probability group predictions
- df_pg = pd.DataFrame(d)
- # create boxplots in order of increasing probability ranges
- props = dict(boxes='slategray', medians='black', whiskers='slategray')
- viz = df_pg.plot.box(color=props, figsize=(15,7), patch_artist=True, rot=45)
- grid = viz.grid(False, axis='x')
- ylab = viz.set_ylabel('Readmission Probability')
- xlab = viz.set_xlabel('Mean Prediction Probability Ranges')
- title = viz.set_title(
- label='Expected Prediction Distributions by Readmission Prediction Range',
- fontsize=18
- )
Python源代碼鏈接:https://blog.datarobot.com/estimation-of-prediction-distributions-using-datarobot
H2O.ai
另一款支持人工智能的服務平臺工具是H2O。它主要被用于完成諸如:無人駕駛的AI結果輸出等方面的機器學習任務。
總結
除了上述提到的工具和軟件庫,市場上也有著諸如:Google AutoML(https://cloud.google.com/automl/)等其他商業類型的解決方案。它們在實現機器學習相關概念的同時,推動了自動化數據的訓練,并能夠提供出色的結果與預測。如今,隨著自動化機器學習效果的凸顯,人工智能技術也得到了不斷地增強,越來越多的企業都能夠從此類系統的輸出結果中持續受益。
原文標題:A Beginner's Guide to Automated Machine Learning: 4 Maturity Models to Understand,作者:Manoj Rupareliya
【51CTO譯稿,合作站點轉載請注明原文譯者和出處為51CTO.com】