偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

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

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

 [[402276]]

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

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

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

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

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

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

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

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

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

決策森林

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

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

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

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

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

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

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

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

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

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

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

代碼示例

下面進(jìn)行示例展示,可以讓使用者簡(jiǎn)單明了。

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

項(xiàng)目地址: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ī)森林模型。目的是根據(jù)一種動(dòng)物的特征來預(yù)測(cè)它的種類。該數(shù)據(jù)集包含數(shù)值和類別特性,并存儲(chǔ)為 csv 文件。

最喜歡隨機(jī)森林?周志華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) 

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

評(píng)估模型

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

  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"

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

解讀模型

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

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

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

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

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

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

  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)] 

在上述示例中,模型通過默認(rèn)超參數(shù)值進(jìn)行訓(xùn)練。作為首個(gè)解決方案而言非常好,但是調(diào)整超參數(shù)可以進(jìn)一步提升模型的質(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é)任編輯:張燕妮 來源: 機(jī)器之心Pro
相關(guān)推薦

2015-09-14 13:41:47

隨機(jī)森林入門攻略

2017-10-18 14:11:20

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

2014-07-07 10:05:57

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

2017-09-25 16:16:49

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

2022-09-25 23:19:01

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

2023-03-13 08:00:00

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

2017-08-04 14:28:40

決策樹隨機(jī)森林CART模型

2023-02-23 08:00:00

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

2023-09-22 10:34:19

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

2023-08-18 09:18:47

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

2024-06-28 13:57:34

2024-11-05 09:42:59

開發(fā)軟件命令行

2023-02-17 08:10:58

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ā)

2018-02-02 15:50:07

決策樹Apache Spar數(shù)據(jù)

2012-02-02 16:42:24

Android用戶

2020-02-10 10:05:12

Linux發(fā)行版Ubuntu
點(diǎn)贊
收藏

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