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

การทำนายผลลัพธ์ด้วย TensorFlow Estimator และ Python


แนวคิด

เรียกเมธอด predict บนข้อมูลใหม่ แสดง predictions และค่าจริง

ใช้ Keras Sequential API, CNN, TensorFlow Text สำหรับ preprocessing sequence, Google Colab

Estimator เป็น high-level model representation รองรับ scaling และ async training

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

for pred_dict, expec in zip(predictions, expected):
    class_id = pred_dict['class_ids'][0]
    probability = pred_dict['probabilities'][class_id]
    print('Prediction is "{}" ({:.1f}%), expected "{}"'.format(
        SPECIES[class_id], 100 * probability, expec)
    )

Credit: TensorFlow Tutorials

ผลลัพธ์

INFO:tensorflow:Calling model_fn.
INFO:tensorflow:Done calling model_fn.
INFO:tensorflow:Graph was finalized.
INFO:tensorflow:Restoring parameters from /tmp/tmpbhg2uvbr/model.ckpt-5000
INFO:tensorflow:Running local_init_op.
INFO:tensorflow:Done running local_init_op.
Prediction is "Setosa" (91.3%), expected "Setosa"
Prediction is "Versicolor" (52.0%), expected "Versicolor"
Prediction is "Virginica" (63.5%), expected "Virginica"

คำอธิบาย

  • เมื่อเรียก predict จะได้ predictions
  • แสดงค่าพร้อม confidence level บนคอนโซล