自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

一行Python代碼訓(xùn)練所有分類或回歸模型

開發(fā) 后端
在本文中,我們將討論如何使用開源Python庫LazyPredict自動(dòng)化模型訓(xùn)練過程。

自動(dòng)化機(jī)器學(xué)習(xí)(自動(dòng)ML)是指自動(dòng)化數(shù)據(jù)科學(xué)模型開發(fā)管道的組件。Automl減少數(shù)據(jù)科學(xué)家的工作量并加快工作流程。Automl可用于自動(dòng)化各種流水線組件,包括數(shù)據(jù)理解,EDA,數(shù)據(jù)處理,模型訓(xùn)練,Quand參數(shù)調(diào)諧等。

[[398921]]

對(duì)于端到端機(jī)器學(xué)習(xí)項(xiàng)目,每個(gè)管道組件的復(fù)雜性取決于項(xiàng)目。有各種自動(dòng)啟用源庫,可加快每個(gè)管道組件。閱讀本文知道8個(gè)自動(dòng)列表庫以自動(dòng)化機(jī)器學(xué)習(xí)管道。

在本文中,我們將討論如何使用開源Python庫LazyPredict自動(dòng)化模型訓(xùn)練過程。

什么是lazypredict?

LazyPredict是一個(gè)開源Python庫,可自動(dòng)化模型訓(xùn)練管道并加快工作流程。LazyPredict在分類數(shù)據(jù)集中約為30個(gè)分類模型,并列出了回歸數(shù)據(jù)集的40個(gè)回歸模型。

LazyPredict與訓(xùn)練有素的型號(hào)一起回到其性能指標(biāo),而無需編寫太多代碼。人們可以比較每個(gè)模型的性能指標(biāo)并調(diào)整最佳模型,以進(jìn)一步提高性能。

安裝:

leazepredict可以使用pypl庫安裝:

  1. pip install lazypredict 

安裝后,可以導(dǎo)入庫進(jìn)行分類和回歸模型的自動(dòng)訓(xùn)練。

  1. from lazypredict.Supervised import LazyRegressor, LazyClassifier 

用法:

LazyPredict支持分類和回歸問題,所以我會(huì)討論兩個(gè)任務(wù)的演示

波士頓住房(回歸)和泰坦尼克號(hào)(分類)DataSet用于演示LazyPredict庫。

分類任務(wù):

LazyPredict的用法非常直觀,類似于Scikit-learn。首先,為分類任務(wù)創(chuàng)建估計(jì)器LazyClassifier的實(shí)例。一個(gè)可以通過定制度量標(biāo)準(zhǔn)進(jìn)行評(píng)估,默認(rèn)情況下,每種型號(hào)將在準(zhǔn)確性,ROC AUC分?jǐn)?shù),F(xiàn)1分?jǐn)?shù)進(jìn)行評(píng)估。

在繼續(xù)進(jìn)行LazyPredict模型訓(xùn)練之前,必須閱讀數(shù)據(jù)集并處理它以使其適合訓(xùn)練。

  1. import pandas as pd 
  2. from sklearn.model_selection import train_test_split 
  3.  
  4. # Read the titanic dataset 
  5. df_cls = pd.read_csv("titanic.csv") 
  6. df_clsdf_cls = df_cls.drop(['PassengerId','Name','Ticket', 'Cabin'], axis=1
  7.  
  8. # Drop instances with null records 
  9. df_clsdf_cls = df_cls.dropna() 
  10.  
  11. # feature processing 
  12. df_cls['Sex'] = df_cls['Sex'].replace({'male':1, 'female':0}) 
  13. df_cls['Embarked'] = df_cls['Embarked'].replace({'S':0, 'C':1, 'Q':2}) 
  14.  
  15. # Creating train test split 
  16. y = df_cls['Survived'] 
  17. X = df_cls.drop(columns=['Survived'], axis=1
  18.  
  19. # Call train test split on the data and capture the results 
  20. X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42test_size=0.2) 

在特征工程和將數(shù)據(jù)分成訓(xùn)練測試數(shù)據(jù)之后,我們可以使用LazyPredict進(jìn)行模型訓(xùn)練。

  1. # LazyClassifier Instance and fiting data 
  2. clsLazyClassifier(ignore_warnings=Falsecustom_metric=None
  3. models, predictions = cls.fit(X_train, X_test, y_train, y_test) 

回歸任務(wù):

類似于分類模型訓(xùn)練,LazyPredict附帶了回歸數(shù)據(jù)集的自動(dòng)模型訓(xùn)練。實(shí)現(xiàn)類似于分類任務(wù),在實(shí)例LazyRegressor中的更改。

  1. import pandas as pd 
  2. from sklearn.model_selection import train_test_split 
  3.  
  4. # read the data 
  5. column_names = ['CRIM', 'ZN', 'INDUS', 'CHAS', 'NOX', 'RM', 'AGE', 'DIS', 'RAD', 'TAX', 'PTRATIO', 'B', 'LSTAT', 'MEDV'] 
  6. df_reg = pd.read_csv("housing.csv", header=Nonedelimiter=r"\s+"names=column_names
  7.  
  8. # Creating train test split 
  9. y = df_reg['MEDV'] 
  10. X = df_reg.drop(columns=['MEDV'], axis=1
  11.  
  12. # Call train_test_split on the data and capture the results 
  13. X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42test_size=0.2) 
  1. reg = LazyRegressor(ignore_warnings=Falsecustom_metric=None
  2. models, predictions = reg.fit(X_train, X_test, y_train, y_test) 

> (Image by Author), Performance metrics of 42 regression models for the Boston Housing dataset

觀察上述性能指標(biāo),Adaboost分類器是分類任務(wù)的最佳性能模型,漸變?cè)鰪?qiáng)的替換機(jī)策略模型是回歸任務(wù)的最佳表現(xiàn)模型。

結(jié)論:

在本文中,我們已經(jīng)討論了LazyPredict庫的實(shí)施,這些庫可以在幾行Python代碼中訓(xùn)練大約70個(gè)分類和回歸模型。它是一個(gè)非常方便的工具,因?yàn)樗o出了模型執(zhí)行的整體情況,并且可以比較每個(gè)模型的性能。

每個(gè)模型都訓(xùn)練,默認(rèn)參數(shù),因?yàn)樗粓?zhí)行HyperParameter調(diào)整。選擇最佳執(zhí)行模型后,開發(fā)人員可以調(diào)整模型以進(jìn)一步提高性能。

謝謝你的閱讀!

本文翻譯自Christopher Tao的文章《Train all Classification or Regression models in one line of Python Code》。

 

責(zé)任編輯:趙寧寧 來源: 今日頭條
相關(guān)推薦

2023-11-10 09:41:44

Python代碼

2016-12-02 08:53:18

Python一行代碼

2021-04-19 10:38:06

代碼開發(fā)工具

2024-09-26 00:11:01

2022-04-09 09:11:33

Python

2020-07-15 09:40:37

代碼Python瀏覽記錄

2022-06-15 11:27:15

開源代碼項(xiàng)目

2020-08-19 10:30:25

代碼Python多線程

2021-11-02 16:25:41

Python代碼技巧

2017-04-13 19:20:18

Python代碼并行任務(wù)

2020-09-28 12:34:38

Python代碼開發(fā)

2020-08-12 14:54:00

Python代碼開發(fā)

2014-02-12 13:43:50

代碼并行任務(wù)

2017-04-05 11:10:23

Javascript代碼前端

2021-08-23 17:49:02

代碼開發(fā)模型

2020-01-10 22:56:56

Python圖像處理Linux

2022-09-28 10:12:50

Python代碼可視化

2024-05-31 13:14:05

2020-04-22 13:56:26

python函數(shù)編程

2021-04-29 22:38:04

Python數(shù)據(jù)庫SQL
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)