Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

การใช้ Boosted Trees ใน TensorFlow ด้วย Python


แนวคิด

Boosted Trees ปรับปรุงประสิทธิภาพการทำนายโดยใช้หลายโมเดลร่วมกัน ผลลัพธ์รวมจากทุกโมเดล

ใช้ Keras Sequential API สร้างโมเดล sequential ที่เลเยอร์แต่ละอันมี 1 input tensor และ 1 output tensor

CNN มีเลเยอร์ convolutional อย่างน้อย 1 เลเยอร์ ใช้สร้างโมเดลเรียนรู้

รันบน Google Colab มี GPU ฟรี

จะดูวิธีเทรน Gradient Boosting Model ด้วย Decision Trees และ tf.estimator API Boosted Trees เป็น ensemble technique รวมการทำนายจากหลายโมเดลต้นไม้ (10s-1000s) ให้ประสิทธิภาพสูง ต้องการ hyperparameter tuning น้อย

ตัวอย่างโค้ด (ส่วนโหลดข้อมูล)

import numpy as np
import pandas as pd
from IPython.display import clear_output
from matplotlib import pyplot as plt

print("Load the dataset")
dftrain = pd.read_csv('https://storage.googleapis.com/tf-datasets/titanic/train.csv')
dfeval = pd.read_csv('https://storage.googleapis.com/tf-datasets/titanic/eval.csv')
print("Delete the column 'survived'")
y_train = dftrain.pop('survived')
y_eval = dfeval.pop('survived')
import tensorflow as tf
tf.random.set_seed(123)

Credit: TensorFlow Tutorials

ผลลัพธ์

Load the dataset
Delete the column 'survived'

คำอธิบาย

  • import packages ที่จำเป็น
  • โหลด dataset Titanic
  • อ่านเป็น CSV
  • ลบคอลัมน์ 'survived' ออก (เป็น label)