ייצור מערכות למידת מכונה: מתי לבצע טרנספורמציה של נתונים?
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
צריך לבצע פיתוח תכונות (טרנספורמציה) של הנתונים הגולמיים. מתי כדאי לבצע טרנספורמציה של נתונים? באופן כללי, אפשר לבצע הנדסת תכונות בשתי התקופות הבאות:
- לפני אימון המודל.
- בזמן אימון המודל.
הגישה הזו כוללת שני שלבים:
- כותבים קוד או משתמשים בכלים מיוחדים
כדי לבצע טרנספורמציה של הנתונים הגולמיים.
- שומרים את הנתונים שעברו טרנספורמציה במקום שבו המודל יכול לקלוט אותם, למשל בדיסק.
יתרונות
- המערכת מבצעת טרנספורמציה של נתונים גולמיים רק פעם אחת.
- המערכת יכולה לנתח את כל מערך הנתונים כדי לקבוע את אסטרטגיית הטרנספורמציה הטובה ביותר.
חסרונות
הטיה בין אימון להצגה מסוכנת יותר כשהמערכת מבצעת הסקה דינמית (אונליין).
במערכת שמשתמשת בהסקה דינמית, בדרך כלל התוכנה שמבצעת את הטרנספורמציה של מערך הנתונים הגולמי שונה מהתוכנה שמספקת את התחזיות, מה שעלול לגרום לסטייה בין אימון לבין שירות.
לעומת זאת, במערכות שמשתמשות בהסקה סטטית (אופליין) יכול להיות שייעשה שימוש באותה תוכנה.
בגישה הזו, הטרנספורמציה היא חלק מקוד המודל. המודל מבצע הטמעה של נתונים גולמיים ומבצע בהם טרנספורמציה.
יתרונות
- עדיין תוכלו להשתמש באותם קבצים של נתונים גולמיים אם תשנו את הטרנספורמציות.
- כך מובטחים לכם אותם טרנספורמציות בזמן האימון ובזמן החיזוי.
חסרונות
- טרנספורמציות מורכבות עלולות להגדיל את זמן האחזור של המודל.
- הטרנספורמציות מתבצעות בכל אצווה.
טרנספורמציה של הנתונים בכל קבוצה יכולה להיות בעייתית. לדוגמה, נניח שאתם רוצים להשתמש בנורמליזציה לפי ציון Z כדי לשנות נתונים מספריים גולמיים. כדי לבצע נורמליזציה לפי ציון z, צריך את הממוצע וסטיית התקן של המאפיין.
עם זאת, אם תבצעו טרנספורמציות לכל קבוצה, תהיה לכם גישה רק לקבוצת נתונים אחת, ולא למערך הנתונים המלא. לכן, אם יש הבדלים משמעותיים בין קבוצות הנתונים, לדוגמה, למספר Z-score של -2.5 בקבוצת נתונים אחת תהיה משמעות שונה מזו של -2.5 בקבוצת נתונים אחרת.
כפתרון עקיף, המערכת יכולה לחשב מראש את הממוצע ואת סטיית התקן של כל מערך הנתונים, ואז להשתמש בהם כקבועים במודל.
אלא אם צוין אחרת, התוכן של דף זה הוא ברישיון Creative Commons Attribution 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)"]]