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

การตรวจสอบ Titanic Dataset ด้วย TensorFlow Estimators


แนวคิด

ตรวจสอบ dataset ด้วย Estimators โดย iterate features แปลงเป็น list แสดงผล

ใช้ Keras Sequential API, CNN, Google Colab เหมือนเดิม

Estimator เป็น high-level representation ของโมเดลสมบูรณ์ใน TensorFlow ออกแบบให้ scale ง่าย รองรับ asynchronous training

จะเทรน Logistic Regression ด้วย tf.estimator API เป็น baseline สำหรับอัลกอริทึมอื่น ใช้ Titanic dataset ทำนายการรอดชีวิตจากเพศ อายุ ชั้นเรียน ฯลฯ

Estimators ใช้ feature columns อธิบายว่าจะตีความ raw input features อย่างไร คาดหวัง numeric vector feature columns ช่วยแปลงแต่ละ feature

ตัวอย่างโค้ด

print("The dataset is being inspected")
ds = make_input_fn(dftrain, y_train, batch_size=10)()
for feature_batch, label_batch in ds.take(1):
    print('Some feature keys are:', list(feature_batch.keys()))
    print()
    print('A batch of class:', feature_batch['class'].numpy())
    print()
    print('A batch of Labels:', label_batch.numpy())

Credit: TensorFlow Tutorials

ผลลัพธ์

The dataset is being inspected
Some feature keys are: ['sex', 'age', 'n_siblings_spouses', 'parch', 'fare', 'class', 'deck', 'embark_town', 'alone']
A batch of class: [b'First' b'First' b'First' b'Third' b'Third' b'Third' b'First' b'Third' b'Second' b'Third']
A batch of Labels: [0 1 1 0 0 0 1 0 0 0]

คำอธิบาย

  • ตรวจสอบ dataset
  • แสดง feature keys, labels, classes บนคอนโซล
  • ทำโดย iterate ผ่าน batch ของ dataset