太棒了!8 個開源自動化框架,輕松搞定機器學習!
自動化機器學習(AutoML)可以幫助機器學習管道中的某些關鍵組件實現(xiàn)自動化。其中機器學習管道包括數(shù)據(jù)理解、數(shù)據(jù)工程、特征工程、模型訓練、超參數(shù)調整、模型監(jiān)控等。
在這篇文章中,我將分享 8 個開源的 autoML 框架:
Auto-Sklearn TPOT Auto-ViML H2O AutoML Auto-Keras MLBox Hyperopt Sklearn AutoGluon
1、Auto-Sklearn
Auto-sklearn 是基于 scikit-learn 軟件包構建的開源 AutoML 庫。它為給定的數(shù)據(jù)集找到最佳性能的模型以及最佳的超參數(shù)集。它包括一些特征工程技術,例如單點編碼,特征歸一化,降維等。該庫使用 Sklearn 估計器來處理分類和回歸問題。
Auto-sklearn 庫適用于中小型數(shù)據(jù)集,不適用于大型數(shù)據(jù)集。
安裝方法
pip install autosklearn
實用示例
import autosklearn.classification
cls = autosklearn.classification.AutoSklearnClassifier()
cls.fit(X_train, y_train)
predictions = cls.predict(X_test)
2、TPOT

TPOT 是開源的 python AutoML 工具,可使用遺傳編程來優(yōu)化機器學習管道。TPOT 體系結構的數(shù)據(jù)流可以在下圖中觀察到。數(shù)據(jù)清理不在 TPOT 體系結構之內,也就是說,處理缺失值,將數(shù)據(jù)集轉換為數(shù)值形式應由數(shù)據(jù)科學家處理。
安裝方法
pip install tpot
實用示例
from tpot import TPOTClassifier
from sklearn.datasets import load_digits
from sklearn.model_selection import train_test_split
digits = load_digits()
X_train, X_test, y_train, y_test = train_test_split(digits.data, digits.target,
train_size=0.75, test_size=0.25, random_state=42)
tpot = TPOTClassifier(generations=5, population_size=50, verbosity=2, random_state=42)
tpot.fit(X_train, y_train)
print(tpot.score(X_test, y_test))
tpot.export('tpot_digits_pipeline.py')
鏈接
https://github.com/EpistasisLab/tpot
3、Auto-ViML
Auto-ViML代表自動變體實現(xiàn)機器學習。TPOT AutoML工具的局限性在于它需要數(shù)字格式的數(shù)據(jù)集。任何遺漏的值處理和數(shù)據(jù)清理工作都應在TPOT實施之前完成。
AutoViML可以解決此問題,因為它可以對數(shù)據(jù)集進行編碼,特征選擇和其他數(shù)據(jù)清理活動。AutoViML相對比TPOT更快,并會生成多個圖形結果以及模型選擇和超參數(shù)優(yōu)化。
安裝方法
pip install autoviml
實用示例
from autoviml.Auto_ViML import Auto_ViML
model, features, trainm, testm = Auto_ViML(
train,
target,
test,
sample_submission,
hyper_param="GS",
feature_reduction=True,
scoring_parameter="weighted-f1",
KMeans_Featurizer=False,
Boosting_Flag=False,
Binning_Flag=False,
Add_Poly=False,
Stacking_Flag=False,
Imbalanced_Flag=False,
verbose=0,
)
4、H2O AutoML
H2O AutoML是 H2O 開發(fā)的框架,可用于使機器學習工作流程自動化,包括在指定時限內自動進行模型訓練和模型的超參數(shù)調整。
H2O AutoML 工具可以進行數(shù)據(jù)預處理,例如數(shù)字編碼,缺失值插補和其他預處理工作流程。最后,它會自動進行模型選擇和超參數(shù)調整,并以模型的排行榜視圖及其性能返回。AutoML還提供了隨時可用的部署代碼。
安裝方法
要安裝h2o,需要一個Java運行環(huán)境,因為h2o是用Java開發(fā)的。
!apt-get install default-jre
!java -version
!pip install h2o
實用示例
import h2o
from h2o.automl import H2OAutoML
aml = H2OAutoML(max_models = 10, seed = 10, exclude_algos = ["StackedEnsemble", "DeepLearning"], verbosity="info", nfolds=0)
aml.train(x = x, y = y, training_frame = churn_train, validation_frame=churn_valid)
5、Auto-Keras
Auto-Keras 是基于深度學習框架 Keras 構建的開源 AutoML 庫,該框架是由 Texas A&M University 的 Datalab 團隊開發(fā)的。AutoKeras自動搜索深度學習模型的體系結構和超參數(shù),并使用訓練數(shù)據(jù)對其進行訓練,最后返回性能最佳的深度學習模型。Auto-Keras遵循經(jīng)典的Scikit-Learn API設計,因此易于使用。
安裝方法
pip3 install autokeras
實用示例
import autokeras as ak
clf = ak.ImageClassifier()
clf.fit(x_train, y_train)
results = clf.predict(x_test)
6、MLBox
MLBox 是功能強大的 AutoML python庫。它提供了以下功能:
快速讀取和分布式數(shù)據(jù)預處理/清理/格式化 高度可靠的功能選擇和泄漏檢測 高維空間中的精確超參數(shù)優(yōu)化 最新的分類和回歸預測模型(深度學習,堆棧,LightGBM等) 用模型解釋進行預測
安裝方法
pip install mlbox
## or
brew install libomp
實用示例
from mlbox.preprocessing import *
from mlbox.optimisation import *
from mlbox.prediction import *
paths = ['train.csv', 'test.csv'] #to modify
target_name = "target" #to modify
data = Reader(sep=",", header = 0, to_hdf5 = True, to_path = 'save', verbose = True).train_test_split(Lpath = paths, target_name = target_name) #reading
7、Hyperopt Sklearn
HyperOpt-Sklearn 包裝了 HyperOpt 庫,該庫是用于貝葉斯優(yōu)化的開源Python庫。它設計用于具有大量超參數(shù)的模型的大規(guī)模優(yōu)化,并允許優(yōu)化過程跨多個內核和多臺機器進行縮放。它允許自動搜索數(shù)據(jù)準備方法,機器學習算法以及用于分類和回歸任務的模型超參數(shù)。
安裝方法
pip install hyperopt
實用示例
from hpsklearn import HyperoptEstimator, sgd
from hyperopt import hp
import numpy as np
sgd_penalty = 'l2'
sgd_loss = hp.pchoice(’loss’, [(0.50, ’hinge’), (0.25, ’log’), (0.25, ’huber’)])
sgd_alpha = hp.loguniform(’alpha’, low=np.log(1e-5), high=np.log(1))
estim = HyperoptEstimator(classifier=sgd(’my_sgd’, penalty=sgd_penalty, loss=sgd_loss, alpha=sgd_alpha))
estim.fit(X_train, y_train)
8、AutoGluon

AutoGluon 是為 AWS 開源的深度學習工作負載而開發(fā)的 autoML 框架。與其他僅支持表格數(shù)據(jù)的autoML庫不同,它還支持圖像分類,對象檢測,文本以及跨圖像的實際應用程序。
適用于ML初學者和專家,AutoGluon具有如下特點:
用幾行代碼為您的數(shù)據(jù)找到深度學習解決方案 自動超參數(shù)調整,模型選擇/架構搜索以及數(shù)據(jù)處理 改進現(xiàn)有的定制模型和數(shù)據(jù)管道
安裝方法
pip install mxnet
pip install autogluon
實用示例
import autogluon as ag
import pandas as pd
import numpy as np
import os,urllib
from autogluon import TabularPrediction as task
BASE_DIR = '/tmp'
OUTPUT_FILE = os.path.join(BASE_DIR, 'churn_data.csv')
churn_data=urllib.request.urlretrieve('https://raw.githubusercontent.com/srivatsan88/YouTubeLI/master/dataset/WA_Fn-UseC_-Telco-Customer-Churn.csv', OUTPUT_FILE)
churn_master_df = pd.read_csv(OUTPUT_FILE)
size = int(0.8*churn_master_df.shape[0])
train_df = churn_master_df[:size]
test_df = churn_master_df[size:]
train_data = task.Dataset(df=train_df)
test_data = task.Dataset(df=test_df)
predictor = task.fit(train_data=train_data, label=label_column, eval_metric='accuracy')
總結
在本文中,我分享來 8 個開源的AutoML庫,這些庫可以自動執(zhí)行重復任務,例如超參數(shù)調整和模型選擇,以加快數(shù)據(jù)科學家的工作。我把每個使用方法的詳細用法已給出,如果你感興趣,可以拿來實踐!
福利時間
李航老師《統(tǒng)計學習方法(第二版)》課件 & 算法代碼全公開了!
領取方式:
長按下方掃碼,關注后后臺發(fā)消息 [李航]
感謝你的分享,點贊,在看三連 
