機器學習技術讓本來不少繁瑣、耗時的操做都能自動實現,大幅提高工做和生活效率,然而爲了實現這一點,首先須要有足夠高質量的 ML 模型,要想得到這東西可並不容易。html
1959年,Arthur Samuel 將機器學習定義爲讓計算機可以無需明確編程而進行學習。在實踐中,這意味着要找到一種算法,能夠從現有數據集中提取模式,而後使用這些模式來構建可很好地泛化到新數據的預測模型。從那時起,人們發明了許多機器學習算法,爲科學家和工程師提供了充足地選擇,幫助他們構建了驚人的應用程序。git
可是豐富的算法也帶來了一個難題:應該選擇哪一種算法?如何可靠地找出哪一種算法在特定業務問題上表現最佳?此外,機器學習算法一般會列出很長的訓練參數(也稱爲超參數),若是想從模型中得到全部額外精度,則須要將其設置爲「恰好合適」。更糟糕的是,算法還須要以特定方式(也稱爲特徵工程)準備和轉換數據,才能實現最佳學習效果,而且咱們還須要選擇最佳實例類型。github
因此實際上,「無需明確編程」這一點到底體如今哪?算法
體如今最近正式發佈的 Amazon SageMaker Autopilot 中!該功能能夠在徹底控制和可見的狀況下,自動建立最佳分類和迴歸機器學習模型。編程
經過使用單個 API 調用或在 Amazon SageMaker Studio 中單擊幾下,SageMaker Autopilot 首先會檢查數據集,並運行大量候選項以找出數據預處理步驟、機器學習算法和超參數的最佳組合。而後,它將使用這種組合來訓練推斷管道,咱們能夠輕鬆地將其部署在實時終端節點上或進行批處理。與 Amazon SageMaker 同樣,全部這些操做都在徹底託管的基礎設施上進行。app
最後一樣重要的是:SageMaker Autopilot 還會生成 Python 代碼,確切顯示數據的預處理方式:咱們不只能夠了解 SageMaker Autopilot 的工做方式,若是願意,還能夠從新使用該代碼進行進一步的手動調整。
截止目前,SageMaker Autopilot 支持:機器學習
讓咱們以這個筆記本示例爲起點:藉此創建一個二進制分類模型,預測客戶是接受仍是拒絕營銷報價。請花幾分鐘閱讀,你們會發現業務問題自己很容易理解,數據集既不大也不復雜。可是須要幾個非直觀的預處理步驟,還須要挑選算法及其參數。而 SageMaker Autopilot 能夠解決這一難題!分佈式
首先獲取數據集的副本,快速瀏覽前幾行:工具
隨後將其上傳到 Amazon Simple Storage Service(S3)中,但不進行任何預處理。性能
sess.upload_data(path="automl-train.csv", key_prefix=prefix + "/input") 's3://sagemaker-us-west-2-123456789012/sagemaker/DEMO-automl-dm/input/automl-train.csv'
隨後配置 AutoML 做業:
input_data_config = [{ 'DataSource': { 'S3DataSource': { 'S3DataType': 'S3Prefix', 'S3Uri': 's3://{}/{}/input'.format(bucket,prefix) } }, 'TargetAttributeName': 'y' } ] output_data_config = { 'S3OutputPath': 's3://{}/{}/output'.format(bucket,prefix) }
就這麼簡單!固然,隨着對於數據和模型的瞭解深刻,SageMaker Autopilot 的許多選項會派上用場,例如:
不過有件事不須要咱們去作,那就是調整訓練集羣的大小,由於 SageMaker Autopilot 會使用基於數據大小和算法的啓發式方法!
無需配置,便可使用 CreateAutoMl API 啓動該做業:
auto_ml_job_name = 'automl-dm-' + timestamp_suffix print('AutoMLJobName: ' + auto_ml_job_name) sm.create_auto_ml_job(AutoMLJobName=auto_ml_job_name, InputDataConfig=input_data_config, OutputDataConfig=output_data_config, RoleArn=role) AutoMLJobName: automl-dm-28-10-17-49
做業分四個步驟運行(可使用 DescribeAutoMlJob API 查看):
達到最大候選項數量(或其中一種中止條件)後,做業完成。隨後可使用 ListCandidatesForAutoMlJob API 獲取有關全部候選項的詳細信息,也能夠在 AWS 控制檯中查看。
candidates = sm.list_candidates_for_auto_ml_job(AutoMLJobName=auto_ml_job_name, SortBy='FinalObjectiveMetricValue')['Candidates'] index = 1 for candidate in candidates: print (str(index) + " " + candidate['CandidateName'] + " " + str(candidate['FinalAutoMLJobObjectiveMetric']['Value'])) index += 1 1 automl-dm-28-tuning-job-1-fabb8-001-f3b6dead 0.9186699986457825 2 automl-dm-28-tuning-job-1-fabb8-004-03a1ff8a 0.918304979801178 3 automl-dm-28-tuning-job-1-fabb8-003-c443509a 0.9181839823722839 4 automl-dm-28-tuning-job-1-ed07c-006-96f31fde 0.9158779978752136 5 automl-dm-28-tuning-job-1-ed07c-004-da2d99af 0.9130859971046448 6 automl-dm-28-tuning-job-1-ed07c-005-1e90fd67 0.9130859971046448 7 automl-dm-28-tuning-job-1-ed07c-008-4350b4fa 0.9119930267333984 8 automl-dm-28-tuning-job-1-ed07c-007-dae75982 0.9119930267333984 9 automl-dm-28-tuning-job-1-ed07c-009-c512379e 0.9119930267333984 10 automl-dm-28-tuning-job-1-ed07c-010-d905669f 0.8873512744903564
目前,假設咱們只對最佳試驗感興趣:驗證準確率爲91.87%。讓咱們將其部署到 SageMaker 終端節點,就像部署任何模型同樣:
model_arn = sm.create_model(Containers=best_candidate['InferenceContainers'], ModelName=model_name, ExecutionRoleArn=role) ep_config = sm.create_endpoint_config(EndpointConfigName = epc_name, ProductionVariants=[{'InstanceType':'ml.m5.2xlarge', 'InitialInstanceCount':1, 'ModelName':model_name, 'VariantName':variant_name}]) create_endpoint_response = sm.create_endpoint(EndpointName=ep_name, EndpointConfigName=epc_name)
幾分鐘後終端節點開始運行,隨後就能夠用它進行預測。這意味着 SageMaker 正常運行!
那麼模型的構建方式以及其餘候選項又有什麼用?下文將詳細介紹。
SageMaker Autopilot 將訓練工件存儲在 S3 中,包括兩個自動生成的筆記本。
job = sm.describe_auto_ml_job(AutoMLJobName=auto_ml_job_name) job_data_notebook = job['AutoMLJobArtifacts']['DataExplorationNotebookLocation'] job_candidate_notebook = job['AutoMLJobArtifacts']['CandidateDefinitionNotebookLocation'] print(job_data_notebook) print(job_candidate_notebook) s3://<PREFIX_REMOVED>/notebooks/SageMakerAutopilotCandidateDefinitionNotebook.ipynb s3://<PREFIX_REMOVED>/notebooks/SageMakerAutopilotDataExplorationNotebook.ipynb
第一個筆記本包含有關數據集的信息:
第二個筆記本包含有關 SageMaker Autopilot 做業的完整詳細信息:候選項、數據預處理步驟等。全部代碼都可用,咱們能夠更改「旋鈕」以進行進一步的實驗。
如上圖所示,咱們能夠徹底控制和查看模型的構建方式。
Amazon SageMaker Autopilot 使機器學習比以往任什麼時候候都更加簡單易用。不管是剛開始機器學習,仍是經驗豐富的從業者,SageMaker Autopilot 均可以幫助咱們使用如下任一途徑更快更好地構建模型:
目前咱們能夠在如下區域使用 SageMaker Autopilot: