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

最喜歡隨機森林?TensorFlow開源決策森林庫TF-DF

新聞 人工智能
近日,TensorFlow 開源了 TensorFlow 決策森林 (TF-DF)。TF-DF 是用于訓(xùn)練、服務(wù)和解釋決策森林模型(包括隨機森林和梯度增強樹)生產(chǎn)方面的 SOTA 算法集合。

 [[402276]]

在人工智能發(fā)展史上,各類算法可謂層出不窮。近十幾年來,深層神經(jīng)網(wǎng)絡(luò)的發(fā)展在機器學(xué)習(xí)領(lǐng)域取得了顯著進展。通過構(gòu)建分層或「深層」結(jié)構(gòu),模型能夠在有監(jiān)督或無監(jiān)督的環(huán)境下從原始數(shù)據(jù)中學(xué)習(xí)良好的表征,這被認為是其成功的關(guān)鍵因素。

而深度森林,是 AI 領(lǐng)域重要的研究方向之一。

2017 年,周志華和馮霽等人提出了深度森林框架,這是首次嘗試使用樹集成來構(gòu)建多層模型的工作。2018 年,周志華等人又在研究《Multi-Layered Gradient Boosting Decision Trees》中探索了多層的決策樹。今年 2 月,周志華團隊開源深度森林軟件包 DF21:訓(xùn)練效率高、超參數(shù)少,在普通設(shè)備就能運行。

就在近日,TensorFlow 開源了 TensorFlow 決策森林 (TF-DF)。TF-DF 是用于訓(xùn)練、服務(wù)和解釋決策森林模型(包括隨機森林和梯度增強樹)生產(chǎn)方面的 SOTA 算法集合?,F(xiàn)在,你可以使用這些模型進行分類、回歸和排序任務(wù),具有 TensorFlow 和 Keras 的靈活性和可組合性。

最喜歡隨機森林?周志華DF21后,TensorFlow開源決策森林庫TF-DF

谷歌大腦研究員、Keras之父François Chollet表示:「現(xiàn)在可以用Keras API訓(xùn)練TensorFlow決策森林了?!?/p>

最喜歡隨機森林?周志華DF21后,TensorFlow開源決策森林庫TF-DF

對于這一開源項目,網(wǎng)友表示:「這非???!隨機森林是我最喜歡的模型?!?/p>

最喜歡隨機森林?周志華DF21后,TensorFlow開源決策森林庫TF-DF

決策森林

決策森林是一系列機器學(xué)習(xí)算法,其質(zhì)量和速度可與神經(jīng)網(wǎng)絡(luò)相競爭(它比神經(jīng)網(wǎng)絡(luò)更易于使用,功能也很強大),實際上與特定類型的數(shù)據(jù)配合使用時,它們比神經(jīng)網(wǎng)絡(luò)更出色,尤其是在處理表格數(shù)據(jù)時。

最喜歡隨機森林?周志華DF21后,TensorFlow開源決策森林庫TF-DF

隨機森林是一種流行的決策森林模型。在這里,你可以看到一群樹通過投票結(jié)果對一個例子進行分類。

決策森林是由許多決策樹構(gòu)建的,它包括隨機森林和梯度提升樹等。這使得它們易于使用和理解,而且可以利用已經(jīng)存在的大量可解釋性工具和技術(shù)進行操作。

最喜歡隨機森林?周志華DF21后,TensorFlow開源決策森林庫TF-DF

決策樹是一系列僅需做出是 / 否判斷的問題,使用決策樹將動物分成雞、貓、袋鼠。

TF-DF 為 TensorFlow 用戶帶來了模型和一套定制工具:

  • 對初學(xué)者來說,開發(fā)和解釋決策森林模型更容易。不需要顯式地列出或預(yù)處理輸入特征(因為決策森林可以自然地處理數(shù)字和分類屬性)、指定體系架構(gòu)(例如,通過嘗試不同的層組合,就像在神經(jīng)網(wǎng)絡(luò)中一樣),或者擔(dān)心模型發(fā)散。一旦你的模型經(jīng)過訓(xùn)練,你就可以直接繪制它或者用易于解釋的統(tǒng)計數(shù)據(jù)來分析它。
  • 高級用戶將受益于推理時間非??斓哪P停ㄔ谠S多情況下,每個示例的推理時間為亞微秒)。而且,這個庫為模型實驗和研究提供了大量的可組合性。特別是,將神經(jīng)網(wǎng)絡(luò)和決策森林相結(jié)合是很容易的。
最喜歡隨機森林?周志華DF21后,TensorFlow開源決策森林庫TF-DF

如上圖所示,只需使用一行代碼就能構(gòu)建模型,相比之下,動圖中的下面代碼是用于構(gòu)建神經(jīng)網(wǎng)絡(luò)的代碼。在 TensorFlow 中,決策森林和神經(jīng)網(wǎng)絡(luò)都使用 Keras。可以使用相同的 API 來實驗不同類型的模型,更重要的是,可以使用相同的工具,例如 TensorFlow Serving 來部署這兩種模型。

以下是 TF-DF 提供的一些功能:

  • TF-DF 提供了一系列 SOTA 決策森林訓(xùn)練和服務(wù)算法,如隨機森林、CART、(Lambda)MART、DART 等。
  • 基于樹的模型與各種 TensorFlow 工具、庫和平臺(如 TFX)更容易集成,TF-DF 庫可以作為通向豐富 TensorFlow 生態(tài)系統(tǒng)的橋梁。
  • 對于神經(jīng)網(wǎng)絡(luò)用戶,你可以使用決策森林這種簡單的方式開始 TensorFlow,并繼續(xù)探索神經(jīng)網(wǎng)絡(luò)。

代碼示例

下面進行示例展示,可以讓使用者簡單明了。

最喜歡隨機森林?周志華DF21后,TensorFlow開源決策森林庫TF-DF

項目地址:https://github.com/tensorflow/decision-forests

  • TF-DF 網(wǎng)站地址:https://www.tensorflow.org/decision_forests
  • Google I/O 2021 地址:https://www.youtube.com/watch?v=5qgk9QJ4rdQ

 

模型訓(xùn)練

在數(shù)據(jù)集 Palmer's Penguins 上訓(xùn)練隨機森林模型。目的是根據(jù)一種動物的特征來預(yù)測它的種類。該數(shù)據(jù)集包含數(shù)值和類別特性,并存儲為 csv 文件。

最喜歡隨機森林?周志華DF21后,TensorFlow開源決策森林庫TF-DF

Palmer's Penguins 數(shù)據(jù)集示例。

模型訓(xùn)練代碼:

  1. # Install TensorFlow Decision Forests 
  2. !pip install tensorflow_decision_forests 
  3. # Load TensorFlow Decision Forests 
  4. import tensorflow_decision_forests as tfdf 
  5. # Load the training dataset using pandas 
  6. import pandas 
  7. train_df = pandas.read_csv("penguins_train.csv"
  8. # Convert the pandas dataframe into a TensorFlow dataset 
  9. train_ds = tfdf.keras.pd_dataframe_to_tf_dataset(train_df, label="species"
  10. # Train the model 
  11. model = tfdf.keras.RandomForestModel() 
  12. model.fit(train_ds) 

請注意,代碼中沒有提供輸入特性或超參數(shù)。這意味著,TensorFlow 決策森林將自動檢測此數(shù)據(jù)集中的輸入特征,并對所有超參數(shù)使用默認值。

評估模型

現(xiàn)在開始對模型的質(zhì)量進行評估:

  1. # Load the testing dataset 
  2. test_df = pandas.read_csv("penguins_test.csv"
  3. # Convert it to a TensorFlow dataset 
  4. test_ds = tfdf.keras.pd_dataframe_to_tf_dataset(test_df, label="species"
  5. # Evaluate the model 
  6. model.compile(metrics=["accuracy"]) 
  7. print(model.evaluate(test_ds)) 
  8. # >> 0.979311 
  9. # Note: Cross-validation would be more suited on this small dataset. 
  10. # See also the "Out-of-bag evaluation" below. 
  11. # Export the model to a TensorFlow SavedModel 
  12. model.save("project/my_first_model"

帶有默認超參數(shù)的隨機森林模型為大多數(shù)問題提供了一個快速和良好的基線。決策森林一般會對中小尺度問題進行快速訓(xùn)練,與其他許多類型的模型相比,需要較少的超參數(shù)調(diào)優(yōu),并且通常會提供強大的結(jié)果。

解讀模型

現(xiàn)在,你已經(jīng)了解了所訓(xùn)練模型的準確率,接下來該考慮它的可解釋性了。如果你希望理解和解讀正被建模的現(xiàn)象、調(diào)試模型或者開始信任其決策,可解釋性就變得非常重要了。如上所述,有大量的工具可用來解讀所訓(xùn)練的模型。首先從 plot 開始:

  1. tfdf.model_plotter.plot_model_in_colab(model, tree_idx=0
最喜歡隨機森林?周志華DF21后,TensorFlow開源決策森林庫TF-DF

其中一棵決策樹的結(jié)構(gòu)。

你可以直觀地看到樹結(jié)構(gòu)。此外,模型統(tǒng)計是對 plot 的補充,統(tǒng)計示例包括:

  • 每個特性使用了多少次?
  • 模型訓(xùn)練的速度有多快(樹的數(shù)量和時間)?
  • 節(jié)點在樹結(jié)構(gòu)中是如何分布的(比如大多數(shù) branch 的長度)?

這些問題的答案以及更多類似查詢的答案都包含在模型概要中,并可以在模型檢查器中訪問。

  1. # Print all the available information about the model 
  2. model.summary() 
  3. >> Input Features (7): 
  4. >>   bill_depth_mm 
  5. >>   bill_length_mm 
  6. >>   body_mass_g>>    
  7. ... 
  8. >> Variable Importance: 
  9. >>   1.    "bill_length_mm" 653.000000 ################ 
  10. >>   ... 
  11. >> Out-of-bag evaluation: accuracy:0.964602 logloss:0.102378 
  12. >> Number of trees: 300 
  13. >> Total number of nodes: 4170 
  14. >>   ... 
  15. # Get feature importance as a array 
  16. model.make_inspector().variable_importances()["MEAN_DECREASE_IN_ACCURACY"
  17. >> [("flipper_length_mm"0.149), 
  18. >>      ("bill_length_mm"0.096), 
  19. >>      ("bill_depth_mm"0.025), 
  20. >>      ("body_mass_g"0.018), 
  21. >>      ("island"0.012)] 

在上述示例中,模型通過默認超參數(shù)值進行訓(xùn)練。作為首個解決方案而言非常好,但是調(diào)整超參數(shù)可以進一步提升模型的質(zhì)量??梢匀缦逻@樣做:

  1. # List all the other available learning algorithms 
  2. tfdf.keras.get_all_models() 
  3. >> [tensorflow_decision_forests.keras.RandomForestModel, 
  4. >>  tensorflow_decision_forests.keras.GradientBoostedTreesModel, 
  5. >>  tensorflow_decision_forests.keras.CartModel] 
  6. # Display the hyper-parameters of the Gradient Boosted Trees model  
  7. ? tfdf.keras.GradientBoostedTreesModel 
  8. >> A GBT (Gradient Boosted [Decision] Tree) is a set of shallow decision trees trained sequentially. Each tree is trained to predict and then "correct" for the errors of the previously trained trees (more precisely each tree predicts the gradient of the loss relative to the model output).. 
  9.     ... 
  10.    Attributes: 
  11.      num_trees: num_trees: Maximum number of decision trees. The effective number of trained trees can be smaller if early stopping is enabled. Default: 300
  12.      max_depth: Maximum depth of the tree. `max_depth=1` means that all trees will be roots. Negative values are ignored. Default: 6
  13.      ... 
  14.      # Create another model with specified hyper-parameters 
  15. model = tfdf.keras.GradientBoostedTreesModel( 
  16.     num_trees=500
  17.     growing_strategy="BEST_FIRST_GLOBAL"
  18.     max_depth=8
  19.     split_axis="SPARSE_OBLIQUE" 
  20.     ,) 
  21. # Evaluate the model 
  22. model.compile(metrics=["accuracy"]) 
  23. print(model.evaluate(test_ds))#  
  24. >> 0.986851 

 

 

責(zé)任編輯:張燕妮 來源: 機器之心Pro
相關(guān)推薦

2017-10-18 14:11:20

機器學(xué)習(xí)決策樹隨機森林

2015-09-14 13:41:47

隨機森林入門攻略

2014-07-07 10:05:57

機械學(xué)習(xí)

2017-09-25 16:16:49

決策樹隨機森林機器學(xué)習(xí)

2022-09-25 23:19:01

機器學(xué)習(xí)決策樹Python

2023-03-13 08:00:00

機器學(xué)習(xí)算法

2017-08-04 14:28:40

決策樹隨機森林CART模型

2023-02-23 08:00:00

Python機器學(xué)習(xí)編程代碼

2023-09-22 10:34:19

學(xué)習(xí)算法隨機森林Java

2023-08-18 09:18:47

信貸違約機器學(xué)習(xí)

2023-02-17 08:10:58

2024-06-28 13:57:34

2024-11-05 09:42:59

開發(fā)軟件命令行

2021-01-14 23:14:40

開源Linux生產(chǎn)力應(yīng)用

2020-08-06 15:14:07

D語言編程語言

2022-04-30 18:42:38

Go編程語言

2012-03-30 13:56:17

編程開發(fā)

2017-05-03 22:05:48

深度學(xué)習(xí)候選采樣深度學(xué)習(xí)庫

2009-06-22 11:47:09

森林防火無線監(jiān)控艾克賽爾

2012-04-28 09:14:50

編程編程語錄
點贊
收藏

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