【機(jī)器學(xué)習(xí)】太棒了!8 個(gè)開源自動(dòng)化機(jī)器學(xué)習(xí)框架,輕松搞定機(jī)器學(xué)習(xí)!
自動(dòng)化機(jī)器學(xué)習(xí)(AutoML)可以幫助機(jī)器學(xué)習(xí)管道中的某些關(guān)鍵組件實(shí)現(xiàn)自動(dòng)化。其中機(jī)器學(xué)習(xí)管道包括數(shù)據(jù)理解、數(shù)據(jù)工程、特征工程、模型訓(xùn)練、超參數(shù)調(diào)整、模型監(jiān)控等。
在這篇文章中,我將分享 8 個(gè)開源的 autoML 框架:
Auto-Sklearn TPOT Auto-ViML H2O AutoML Auto-Keras MLBox Hyperopt Sklearn AutoGluon
1、Auto-Sklearn
Auto-sklearn 是基于 scikit-learn 軟件包構(gòu)建的開源 AutoML 庫(kù)。它為給定的數(shù)據(jù)集找到最佳性能的模型以及最佳的超參數(shù)集。它包括一些特征工程技術(shù),例如單點(diǎn)編碼,特征歸一化,降維等。該庫(kù)使用 Sklearn 估計(jì)器來處理分類和回歸問題。
Auto-sklearn 庫(kù)適用于中小型數(shù)據(jù)集,不適用于大型數(shù)據(jù)集。
安裝方法
pip install autosklearn
實(shí)用示例
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)化機(jī)器學(xué)習(xí)管道。TPOT 體系結(jié)構(gòu)的數(shù)據(jù)流可以在下圖中觀察到。數(shù)據(jù)清理不在 TPOT 體系結(jié)構(gòu)之內(nèi),也就是說,處理缺失值,將數(shù)據(jù)集轉(zhuǎn)換為數(shù)值形式應(yīng)由數(shù)據(jù)科學(xué)家處理。
安裝方法
pip install tpot
實(shí)用示例
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代表自動(dòng)變體實(shí)現(xiàn)機(jī)器學(xué)習(xí)。TPOT AutoML工具的局限性在于它需要數(shù)字格式的數(shù)據(jù)集。任何遺漏的值處理和數(shù)據(jù)清理工作都應(yīng)在TPOT實(shí)施之前完成。
AutoViML可以解決此問題,因?yàn)樗梢詫?duì)數(shù)據(jù)集進(jìn)行編碼,特征選擇和其他數(shù)據(jù)清理活動(dòng)。AutoViML相對(duì)比TPOT更快,并會(huì)生成多個(gè)圖形結(jié)果以及模型選擇和超參數(shù)優(yōu)化。
安裝方法
pip install autoviml
實(shí)用示例
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ā)的框架,可用于使機(jī)器學(xué)習(xí)工作流程自動(dòng)化,包括在指定時(shí)限內(nèi)自動(dòng)進(jìn)行模型訓(xùn)練和模型的超參數(shù)調(diào)整。
H2O AutoML 工具可以進(jìn)行數(shù)據(jù)預(yù)處理,例如數(shù)字編碼,缺失值插補(bǔ)和其他預(yù)處理工作流程。最后,它會(huì)自動(dòng)進(jìn)行模型選擇和超參數(shù)調(diào)整,并以模型的排行榜視圖及其性能返回。AutoML還提供了隨時(shí)可用的部署代碼。
安裝方法
要安裝h2o,需要一個(gè)Java運(yùn)行環(huán)境,因?yàn)閔2o是用Java開發(fā)的。
!apt-get install default-jre
!java -version
!pip install h2o
實(shí)用示例
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 是基于深度學(xué)習(xí)框架 Keras 構(gòu)建的開源 AutoML 庫(kù),該框架是由 Texas A&M University 的 Datalab 團(tuán)隊(duì)開發(fā)的。AutoKeras自動(dòng)搜索深度學(xué)習(xí)模型的體系結(jié)構(gòu)和超參數(shù),并使用訓(xùn)練數(shù)據(jù)對(duì)其進(jìn)行訓(xùn)練,最后返回性能最佳的深度學(xué)習(xí)模型。Auto-Keras遵循經(jīng)典的Scikit-Learn API設(shè)計(jì),因此易于使用。
安裝方法
pip3 install autokeras
實(shí)用示例
import autokeras as ak
clf = ak.ImageClassifier()
clf.fit(x_train, y_train)
results = clf.predict(x_test)
6、MLBox
MLBox 是功能強(qiáng)大的 AutoML python庫(kù)。它提供了以下功能:
快速讀取和分布式數(shù)據(jù)預(yù)處理/清理/格式化 高度可靠的功能選擇和泄漏檢測(cè) 高維空間中的精確超參數(shù)優(yōu)化 最新的分類和回歸預(yù)測(cè)模型(深度學(xué)習(xí),堆棧,LightGBM等) 用模型解釋進(jìn)行預(yù)測(cè)
安裝方法
pip install mlbox
## or
brew install libomp
實(shí)用示例
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 庫(kù),該庫(kù)是用于貝葉斯優(yōu)化的開源Python庫(kù)。它設(shè)計(jì)用于具有大量超參數(shù)的模型的大規(guī)模優(yōu)化,并允許優(yōu)化過程跨多個(gè)內(nèi)核和多臺(tái)機(jī)器進(jìn)行縮放。它允許自動(dòng)搜索數(shù)據(jù)準(zhǔn)備方法,機(jī)器學(xué)習(xí)算法以及用于分類和回歸任務(wù)的模型超參數(shù)。
安裝方法
pip install hyperopt
實(shí)用示例
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 開源的深度學(xué)習(xí)工作負(fù)載而開發(fā)的 autoML 框架。與其他僅支持表格數(shù)據(jù)的autoML庫(kù)不同,它還支持圖像分類,對(duì)象檢測(cè),文本以及跨圖像的實(shí)際應(yīng)用程序。
適用于ML初學(xué)者和專家,AutoGluon具有如下特點(diǎn):
用幾行代碼為您的數(shù)據(jù)找到深度學(xué)習(xí)解決方案 自動(dòng)超參數(shù)調(diào)整,模型選擇/架構(gòu)搜索以及數(shù)據(jù)處理 改進(jìn)現(xiàn)有的定制模型和數(shù)據(jù)管道
安裝方法
pip install mxnet
pip install autogluon
實(shí)用示例
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')
總結(jié)
在本文中,我分享來 8 個(gè)開源的AutoML庫(kù),這些庫(kù)可以自動(dòng)執(zhí)行重復(fù)任務(wù),例如超參數(shù)調(diào)整和模型選擇,以加快數(shù)據(jù)科學(xué)家的工作。
往期精彩回顧
本站qq群851320808,加入微信群請(qǐng)掃碼:
