ระบบ ML การผลิต: ควรเปลี่ยนรูปแบบข้อมูลเมื่อใด
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ข้อมูลดิบต้องได้รับการวิศวกรรมฟีเจอร์ (เปลี่ยนรูปแบบ) คุณควรเปลี่ยนรูปแบบข้อมูลเมื่อใด โดยทั่วไปแล้ว คุณสามารถสร้างชิ้นงานได้ในช่วงใดช่วงหนึ่งต่อไปนี้
แนวทางนี้ประกอบด้วย 2 ขั้นตอน ดังนี้
- เขียนโค้ดหรือใช้เครื่องมือเฉพาะทาง
เพื่อเปลี่ยนรูปแบบข้อมูลดิบ
- จัดเก็บข้อมูลที่แปลงแล้วไว้ในที่ที่โมเดลสามารถนำเข้าได้ เช่น ในดิสก์
ข้อดี
- ระบบจะเปลี่ยนรูปแบบข้อมูลดิบเพียงครั้งเดียว
- ระบบสามารถวิเคราะห์ชุดข้อมูลทั้งหมดเพื่อกำหนดกลยุทธ์การเปลี่ยนรูปแบบที่ดีที่สุด
ข้อเสีย
ความเอียงของข้อมูลที่ใช้ฝึกกับข้อมูลที่ใช้ให้บริการจะอันตรายมากขึ้นเมื่อระบบทำการอนุมานแบบไดนามิก (ออนไลน์)
ในระบบที่ใช้การอนุมานแบบไดนามิก ซอฟต์แวร์ที่เปลี่ยนรูปแบบชุดข้อมูลดิบมักจะแตกต่างจากซอฟต์แวร์ที่แสดงการคาดการณ์ ซึ่งอาจทําให้การฝึกและการนําเสนอข้อมูลมีความเบี่ยงเบน
ในทางตรงกันข้าม ระบบที่ใช้การอนุมานแบบคงที่ (ออฟไลน์) อาจใช้ซอฟต์แวร์เดียวกันในบางครั้ง
ในกรณีนี้ การเปลี่ยนรูปแบบเป็นส่วนหนึ่งของโค้ดโมเดล โมเดลจะส่งผ่านข้อมูลดิบและเปลี่ยนรูปแบบข้อมูล
ข้อดี
- คุณยังคงใช้ไฟล์ข้อมูลดิบเดิมได้หากเปลี่ยนการเปลี่ยนรูปแบบ
- คุณจะได้รับการเปลี่ยนรูปแบบเดียวกันในเวลาที่ฝึกและเวลาทำนาย
ข้อเสีย
- การแปลงที่ซับซ้อนอาจเพิ่มเวลาในการตอบสนองของโมเดล
- การเปลี่ยนรูปแบบจะเกิดขึ้นกับแต่ละกลุ่ม
การเปลี่ยนรูปแบบข้อมูลต่อกลุ่มอาจเป็นเรื่องยาก ตัวอย่างเช่น สมมติว่าคุณต้องการใช้การปรับมาตรฐานคะแนน Z เพื่อเปลี่ยนรูปแบบข้อมูลตัวเลขดิบ การทำให้เป็นมาตรฐานตามคะแนน z ต้องใช้ค่าเฉลี่ยและค่าเบี่ยงเบนมาตรฐานของฟีเจอร์
อย่างไรก็ตาม การเปลี่ยนรูปแบบต่อกลุ่มหมายความว่าคุณจะมีสิทธิ์เข้าถึงข้อมูล 1 กลุ่มเท่านั้น ไม่ใช่ทั้งชุดข้อมูล ดังนั้น หากกลุ่มมีความแปรปรวนสูง ค่า Z-Score เช่น -2.5 ใน 1 กลุ่มจะไม่มีความหมายเหมือนกับ -2.5 ในอีกกลุ่ม
วิธีแก้ปัญหาคือระบบจะคํานวณค่ามัธยฐานและค่าเบี่ยงเบนมาตรฐานล่วงหน้าจากทั้งชุดข้อมูล แล้วนําไปใช้เป็นค่าคงที่ในโมเดล
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-27 UTC
[null,null,["อัปเดตล่าสุด 2025-07-27 UTC"],[[["\u003cp\u003eFeature engineering can be performed before or during model training, each with its own advantages and disadvantages.\u003c/p\u003e\n"],["\u003cp\u003eTransforming data before training allows for a one-time transformation of the entire dataset but requires careful recreation of transformations during prediction to avoid training-serving skew.\u003c/p\u003e\n"],["\u003cp\u003eTransforming data during training ensures consistency between training and prediction but can increase model latency and complicate batch processing.\u003c/p\u003e\n"],["\u003cp\u003eWhen transforming data during training, considerations such as Z-score normalization across batches with varying distributions need to be addressed.\u003c/p\u003e\n"]]],[],null,["# Production ML systems: When to transform data?\n\nRaw data must be feature engineered (transformed). When should you transform\ndata? Broadly speaking, you can perform feature engineering during either of\nthe following two periods:\n\n- *Before* training the model.\n- *While* training the model.\n\nTransforming data before training\n---------------------------------\n\nIn this approach, you follow two steps:\n\n1. Write code or use specialized tools to transform the raw data.\n2. Store the transformed data somewhere that the model can ingest, such as on disk.\n\nAdvantages\n\n- The system transforms raw data only once.\n- The system can analyze the entire dataset to determine the best transformation strategy.\n\nDisadvantages\n\n- You must recreate the transformations at prediction time. Beware of [**training-serving skew**](/machine-learning/glossary#training-serving-skew)!\n\nTraining-serving skew is more dangerous when your system performs dynamic\n(online) inference.\nOn a system that uses dynamic inference, the software that transforms\nthe raw dataset usually differs from the software that serves predictions,\nwhich can cause training-serving skew.\nIn contrast, systems that use static (offline) inference can sometimes\nuse the same software.\n\nTransforming data while training\n--------------------------------\n\nIn this approach, the transformation is part of the model code. The model\ningests raw data and transforms it.\n\nAdvantages\n\n- You can still use the same raw data files if you change the transformations.\n- You're ensured the same transformations at training and prediction time.\n\nDisadvantages\n\n- Complicated transforms can increase model latency.\n- Transformations occur for each and every batch.\n\nTransforming the data per batch can be tricky. For example, suppose you want to\nuse [**Z-score normalization**](/machine-learning/glossary#z-score-normalization)\nto transform raw numerical data. Z-score normalization requires the mean and\nstandard deviation of the feature.\nHowever, transformations per batch mean you'll only have access to\n*one batch of data*, not the full dataset. So, if the batches are highly\nvariant, a Z-score of, say, -2.5 in one batch won't have the same meaning\nas -2.5 in another batch.\nAs a workaround, your system can precompute the mean and standard deviation\nacross the entire dataset and then use them as constants in the model.\n| **Key terms:**\n|\n| - [Training-serving skew](/machine-learning/glossary#training-serving-skew)\n- [Z-score normalization](/machine-learning/glossary#z-score-normalization) \n[Help Center](https://support.google.com/machinelearningeducation)"]]