تنظيم صفحاتك في مجموعات يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
تُخصّص جميع مشاريع هندسة البرامج الجيدة قدرًا كبيرًا من الجهد لمحاولة اختبار تطبيقاتها. وبالمثل، ننصحك بشدة باختبار نموذج الذكاء الاصطناعي لتحديد صحة توقّعاته.
مجموعات التدريب والتحقّق والاختبار
يجب اختبار النموذج على مجموعة مختلفة من الأمثلة عن تلك التي تم استخدامها لتدريب النموذج. كما ستتعرّف عليه لاحقًا، يشكّل الاختبار على أمثلة مختلفة دليلاً أقوى على ملاءمة نموذجك مقارنةً بالاختبار على المجموعة نفسها من الأمثلة. من أين تحصل على هذه الأمثلة المختلفة؟ في العادة، في تعلُّم الآلة، يمكنك الحصول على هذه الأمثلة المختلفة من خلال تقسيم مجموعة البيانات الأصلية. يمكنك بالتالي افتراض أنّه عليك تقسيم مجموعة البيانات الأصلية إلى مجموعتَين فرعيتَين:
لنفترض أنّك تدرّبت على مجموعة التدريب واختبرت على مجموعة الاختبار على مدار جولات متعددة. في كل جولة، تستخدِم نتائج مجموعة الاختبار للتوجيه بشأن كيفية تعديل مَعلمات الخوارزميات الفائقة ومجموعة الميزات. هل يمكنك رؤية أي خطأ في هذا النهج؟ اختَر إجابة واحدة فقط.
قد يؤدي إجراء العديد من الجولات من هذا الإجراء إلى ملاءمة النموذج بشكل ضمني لخصائص مجموعة الاختبار.
نعم. كلما زاد عدد المرات التي تستخدم فيها مجموعة الاختبار نفسها، زادت احتمالية توافق النموذج بشكل وثيق مع مجموعة الاختبار. مثل المعلّم الذي يُعلّم الطلاب من أجل اجتياز الاختبار، يلائم النموذج بدون قصد مجموعة الاختبار، ما قد يجعل من الصعب عليه أن يلائم البيانات الواقعية.
هذا النهج مناسب. بعد كل شيء، يتم التدريب على مجموعة التدريب ويتم التقييم على مجموعة اختبار منفصلة.
في الواقع، هناك مشكلة بسيطة هنا. فكِّر في ما قد يؤدي إلى حدوث مشاكل تدريجية.
هذه الطريقة غير فعّالة من الناحية الحسابية. لا تغيِّر مَعلمات الخوارزميات الفائقة أو مجموعات الميزات بعد كل جولة من الاختبار.
إنّ إجراء الاختبارات بشكل متكرر يكلّف الكثير من المال، ولكنه أمر مهم. ومع ذلك، فإنّ الاختبار المتكرّر أقل تكلفة بكثير من التدريب الإضافي. يمكن أن يؤدي تحسين المَعلمات الفائقة ومجموعة الميزات إلى تحسين جودة النموذج بشكلٍ كبير، لذا عليك دائمًا تخصيص الوقت والموارد الحسابية للعمل على هذه المَعلمات.
إنّ تقسيم مجموعة البيانات إلى مجموعتَين فكرة جيدة، ولكن النهج الأفضل هو تقسيم مجموعة البيانات إلى ثلاث مجموعات فرعية. بالإضافة إلى مجموعة التدريب ومجموعة الاختبار، تكون المجموعة الفرعية الثالثة هي:
استخدِم مجموعة التحقّق لتقييم النتائج من مجموعة التدريب. بعد أن يشير الاستخدام المتكرّر لمجموعة التحقّق إلى أنّ نموذجك يقدّم تنبؤات جيدة، استخدِم مجموعة الاختبار للتحقّق من صحة نموذجك.
يوضّح الشكل التالي سير العمل هذا. في الشكل، تعني "تعديل النموذج" تعديل أيّ شيء في النموذج ، بدءًا من تغيير معدّل التعلّم وإضافة ميزات أو إزالتها ووصولاً إلى تصميم نموذج جديد تمامًا من الصفر.
الشكل 10. سير عمل جيد للتطوير والاختبار
سير العمل المعروض في الشكل 10 هو الأمثل، ولكن حتى مع سير العمل هذا، لا تزال مجموعات الاختبار ومجموعات التحقّق "تتلاشى" مع الاستخدام المتكرّر. وهذا يعني أنّه كلما زاد استخدامك للبيانات نفسها لاتّخاذ قرارات بشأن إعدادات مُدخلات الضبط أو تحسينات أخرى على النموذج، انخفضت ثقتك في أنّ النموذج سيقدّم توقّعات جيدة استنادًا إلى البيانات الجديدة. لهذا السبب، من المستحسن جمع المزيد من البيانات "لإعادة تحميل" مجموعة الاختبار ومجموعة التحقّق. إنّ بدء صفحة جديدة هو طريقة رائعة لإعادة الضبط.
التمرين: التحقّق من حدسك
لقد خلطت جميع الأمثلة في مجموعة البيانات وقسمت الأمثلة المُخلطة إلى مجموعات تدريب ومجموعة التحقّق ومجموعة اختبار. ومع ذلك، فإنّ قيمة الخسارة في مجموعة الاختبار منخفضة بشكلٍ مذهل ما يثير شكوكك في حدوث خطأ. ما الذي قد يكون حدث؟
إنّ العديد من الأمثلة في مجموعة الاختبار هي نُسخ طبق الأصل من الأمثلة في مجموعة التدريب.
نعم. وقد يشكّل ذلك مشكلة في مجموعة بيانات تحتوي على الكثير من الأمثلة المكرّرة. ننصحك بشدة بحذف الأمثلة المكرّرة من مجموعة الاختبار قبل الاختبار.
التدريب والاختبار غير محدّدَين. في بعض الأحيان، قد يكون خسائر الاختبار منخفضة جدًا بغير قصد. يُرجى إعادة إجراء الاختبار لتأكيد النتيجة.
على الرغم من أنّ الخسارة تختلف قليلاً في كلّ عملية تنفيذ، إلا أنّها يجب ألا تختلف كثيرًا إلى درجة أن تعتقد أنّك ربحت جائزة اليانصيب في التعلم الآلي.
من قبيل الصدفة، احتوت مجموعة الاختبار على أمثلة حقق فيها النموذج أداءً جيدًا.
تم ترتيب الأمثلة بشكل عشوائي، لذا من غير المرجّح حدوث ذلك.
مشاكل إضافية في مجموعات الاختبار
كما يوضّح السؤال السابق، يمكن أن تؤثّر الأمثلة المكرّرة في تقييم النموذج. بعد تقسيم مجموعة بيانات إلى مجموعات تدريب ومجموعة التحقّق ومجموعة الاختبار، احذِف أي أمثلة في مجموعة التحقّق أو مجموعة الاختبار تكون نُسخًا مكرّرة من الأمثلة في مجموعة التدريب. الاختبار العادل الوحيد للنموذج هو اختباره على أمثلة جديدة، وليس النُسخ المكرّرة.
على سبيل المثال، نأخذ نموذجًا يتوقّع ما إذا كانت الرسالة الإلكترونية غير مرغوب فيها، وذلك باستخدام سطر الموضوع ونص الرسالة الإلكترونية وعنوان البريد الإلكتروني للمُرسِل كميزات. لنفترض أنّك قسمت البيانات إلى مجموعتَي تدريب واختبار بنسبة 80-20. بعد التدريب، يحقّق النموذج دقة بنسبة% 99 في كلّ من مجموعة التدريب و مجموعة الاختبار. من المرجّح أن تتوقّع دقة أقل في مجموعة الاختبار، لذا ألقِ نظرة أخرى على البيانات وتبيّن لك أنّ العديد من الأمثلة في مجموعة الاختبار هي نُسخ طبق الأصل من الأمثلة في مجموعة التدريب. المشكلة هي أنّك تجاهلت إزالة الإدخالات المكرّرة للرسالة الإلكترونية غير المرغوب فيها نفسها من قاعدة بيانات الإدخال قبل تقسيم البيانات. إذا تمّ تدريب النموذج عن غير قصد على بعض بيانات الاختبار
باختصار، تستوفي مجموعة الاختبار أو مجموعة التحقّق الجيدة جميع المعايير التالية:
أن تكون كبيرة بما يكفي لتقديم نتائج اختبار ذات دلالة إحصائية
تمثيل مجموعة البيانات ككل بعبارة أخرى، لا تختَر مجموعة اختبار لها خصائص مختلفة عن مجموعة التدريب.
تمثيل البيانات الواقعية التي سيصادفها النموذج كجزء من الغرض التجاري
لا تتوفّر أمثلة مكرّرة في مجموعة التدريب.
تمارين: التحقّق من فهمك
في حال توفّر مجموعة بيانات واحدة تتضمّن عددًا ثابتًا من الأمثلة، أيّ من العبارات التالية صحيحة؟
كل مثال مستخدَم في اختبار النموذج هو مثال واحد أقل مستخدَم في تدريب النموذج.
إنّ تقسيم الأمثلة إلى مجموعات تدريب/اختبار/تحقّق هو لعبة صفرية. وهذا هو الخيار المركزي.
يجب أن يكون عدد الأمثلة في مجموعة الاختبار أكبر من عدد الأمثلة في مجموعة التحقّق.
من الناحية النظرية، يجب أن تحتوي مجموعة التحقّق والاختبار على عدد الأمثلة نفسه أو ما يقارب ذلك.
يجب أن يكون عدد الأمثلة في مجموعة الاختبار أكبر من عدد الأمثلة في مجموعة التحقّق أو مجموعة التدريب.
يكون عدد الأمثلة في مجموعة التدريب عادةً أكبر من عدد الأمثلة في مجموعة التحقّق أو مجموعة الاختبار، ومع ذلك، لا توجد متطلبات نسب مئوية للمجموعات المختلفة.
لنفترض أنّ مجموعة الاختبار تحتوي على أمثلة كافية لإجراء اختبار ذو دلالة إحصائية. بالإضافة إلى ذلك، يؤدّي الاختبار على مجموعة الاختبار إلى خسارة منخفضة. ومع ذلك، كان أداء النموذج ضعيفًا في العالم الحقيقي. ما هي الإجراءات التي عليك اتخاذها؟
حدِّد كيف تختلف مجموعة البيانات الأصلية عن البيانات الواقعية.
نعم. حتى أفضل مجموعات البيانات هي مجرد لقطة من البيانات الواقعية، لأنّ الحقيقة الأساسية الأساسية تميل إلى التغيير بمرور الوقت. على الرغم من أنّ مجموعة الاختبار تطابقت مع مجموعة التدريب بشكلٍ جيد بما يكفي للإشارة إلى جودة النموذج الجيدة، من المحتمل أنّ مجموعة البيانات لا تتطابق بشكلٍ كافٍ مع البيانات في العالم الواقعي. قد تحتاج إلى إعادة التدريب وإعادة الاختبار باستخدام مجموعة بيانات جديدة.
إعادة الاختبار على مجموعة الاختبار نفسها قد تكون نتائج الاختبار غير عادية.
على الرغم من أنّ إعادة الاختبار قد تؤدي إلى نتائج مختلفة قليلاً، من المحتمل أنّ هذه الخطّة ليست مفيدة جدًا.
كم عدد الأمثلة التي يجب أن تحتوي عليها مجموعة الاختبار؟
تاريخ التعديل الأخير: 2025-01-03 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","easyToUnderstand","thumb-up"],["ساعَدني المحتوى في حلّ مشكلتي.","solvedMyProblem","thumb-up"],["غير ذلك","otherUp","thumb-up"]],[["لا يحتوي على المعلومات التي أحتاج إليها.","missingTheInformationINeed","thumb-down"],["الخطوات معقدة للغاية / كثيرة جدًا.","tooComplicatedTooManySteps","thumb-down"],["المحتوى قديم.","outOfDate","thumb-down"],["ثمة مشكلة في الترجمة.","translationIssue","thumb-down"],["مشكلة في العيّنات / التعليمات البرمجية","samplesCodeIssue","thumb-down"],["غير ذلك","otherDown","thumb-down"]],["تاريخ التعديل الأخير: 2025-01-03 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\u003cp\u003eMachine learning models should be tested against a separate dataset, called the test set, to ensure accurate predictions on unseen data.\u003c/p\u003e\n"],["\u003cp\u003eIt's recommended to split the dataset into three subsets: training, validation, and test sets, with the validation set used for initial testing during training and the test set used for final evaluation.\u003c/p\u003e\n"],["\u003cp\u003eThe validation and test sets can "wear out" with repeated use, requiring fresh data to maintain reliable evaluation results.\u003c/p\u003e\n"],["\u003cp\u003eA good test set is statistically significant, representative of the dataset and real-world data, and contains no duplicates from the training set.\u003c/p\u003e\n"],["\u003cp\u003eIt's crucial to address discrepancies between the dataset used for training and testing and the real-world data the model will encounter to achieve satisfactory real-world performance.\u003c/p\u003e\n"]]],[],null,["All good software engineering projects devote considerable energy to\n*testing* their apps. Similarly, we strongly recommend testing your\nML model to determine the correctness of its predictions.\n\nTraining, validation, and test sets\n\nYou should test a model against a *different* set of examples than those\nused to train the model. As you'll learn\n[a little later](#additional_problems_with_test_sets), testing\non different examples is stronger proof of your model's fitness than testing\non the same set of examples.\nWhere do you get those different examples? Traditionally in machine learning,\nyou get those different examples by splitting the original dataset. You might\nassume, therefore, that you should split the original dataset into two subsets:\n\n- A [**training set**](/machine-learning/glossary#training-set) that the model trains on.\n- A [**test set**](/machine-learning/glossary#test-set) for evaluation of the trained model.\n\n**Figure 8.** Not an optimal split.\n\nExercise: Check your intuition \nSuppose you train on the training set and evaluate on the test set over multiple rounds. In each round, you use the test set results to guide how to update hyperparameters and the feature set. Can you see anything wrong with this approach? Pick only one answer. \nDoing many rounds of this procedure might cause the model to implicitly fit the peculiarities of the test set. \nYes! The more often you use the same test set, the more likely the model closely fits the test set. Like a teacher \"teaching to the test,\" the model inadvertently fits the test set, which might make it harder for the model to fit real-world data. \nThis approach is fine. After all, you're training on the training set and evaluating on a separate test set. \nActually, there's a subtle issue here. Think about what might gradually go wrong. \nThis approach is computationally inefficient. Don't change hyperparameters or feature sets after each round of testing. \nFrequent testing is expensive but critical. However, frequent testing is far less expensive than additional training. Optimizing hyperparameters and the feature set can dramatically improve model quality, so always budget time and computational resources to work on these.\n\nDividing the dataset into two sets is a decent idea, but\na better approach is to divide the dataset into *three* subsets.\nIn addition to the training set and the test set, the third subset is:\n\n- A [**validation set**](/machine-learning/glossary#validation-set) performs the initial testing on the model as it is being trained.\n\n**Figure 9.** A much better split.\n\nUse the **validation set** to evaluate results from the training set.\nAfter repeated use of the validation set suggests that your model is\nmaking good predictions, use the test set to double-check your model.\n\nThe following figure suggests this workflow.\nIn the figure, \"Tweak model\" means adjusting anything about the model\n---from changing the learning rate, to adding or removing\nfeatures, to designing a completely new model from scratch.\n**Figure 10.** A good workflow for development and testing. **Note:** When you transform a feature in your training set, you must make the *same* transformation in the validation set, test set, and real-world dataset.\n\nThe workflow shown in Figure 10 is optimal, but even with that workflow,\ntest sets and validation sets still \"wear out\" with repeated use.\nThat is, the more you use the same data to make decisions about\nhyperparameter settings or other model improvements, the less confidence\nthat the model will make good predictions on new data.\nFor this reason, it's a good idea to collect more data to \"refresh\" the test\nset and validation set. Starting anew is a great reset.\n\nExercise: Check your intuition \nYou shuffled all the examples in the dataset and divided the shuffled examples into training, validation, and test sets. However, the loss value on your test set is so staggeringly low that you suspect a mistake. What might have gone wrong? \nMany of the examples in the test set are duplicates of examples in the training set. \nYes. This can be a problem in a dataset with a lot of redundant examples. We strongly recommend deleting duplicate examples from the test set before testing. \nTraining and testing are nondeterministic. Sometimes, by chance, your test loss is incredibly low. Rerun the test to confirm the result. \nAlthough loss does vary a little on each run, it shouldn't vary so much that you think you won the machine learning lottery. \nBy chance, the test set just happened to contain examples that the model performed well on. \nThe examples were well shuffled, so this is extremely unlikely.\n\nAdditional problems with test sets\n\nAs the previous question illustrates, duplicate examples can affect model evaluation.\nAfter splitting a dataset into training, validation, and test sets,\ndelete any examples in the validation set or test set that are duplicates of\nexamples in the training set. The only fair test of a model is against\nnew examples, not duplicates.\n\nFor example, consider a model that predicts whether an email is spam, using\nthe subject line, email body, and sender's email address as features.\nSuppose you divide the data into training and test sets, with an 80-20 split.\nAfter training, the model achieves 99% precision on both the training set and\nthe test set. You'd probably expect a lower precision on the test set, so you\ntake another look at the data and discover that many of the examples in the test\nset are duplicates of examples in the training set. The problem is that you\nneglected to scrub duplicate entries for the same spam email from your input\ndatabase before splitting the data. You've inadvertently trained on some of\nyour test data.\n\nIn summary, a good test set or validation set meets all of the\nfollowing criteria:\n\n- Large enough to yield statistically significant testing results.\n- Representative of the dataset as a whole. In other words, don't pick a test set with different characteristics than the training set.\n- Representative of the real-world data that the model will encounter as part of its business purpose.\n- Zero examples duplicated in the training set.\n\nExercises: Check your understanding \nGiven a single dataset with a fixed number of examples, which of the following statements is true? \nEvery example used in testing the model is one less example used in training the model. \nDividing examples into train/test/validation sets is a zero-sum game. This is the central trade-off. \nThe number of examples in the test set must be greater than the number of examples in the validation set. \nIn theory, the validation set and test test should contain the same number of examples or nearly so. \nThe number of examples in the test set must be greater than the number of examples in the validation set or training set. \nThe number of examples in the training set is usually greater than the number of examples in the validation set or test set; however, there are no percentage requirements for the different sets. \nSuppose your test set contains enough examples to perform a statistically significant test. Furthermore, testing against the test set yields low loss. However, the model performed poorly in the real world. What should you do? \nDetermine how the original dataset differs from real-life data. \nYes. Even the best datasets are only a snapshot of real-life data; the underlying [ground truth](/machine-learning/glossary#ground-truth) tends to change over time. Although your test set matched your training set well enough to suggest good model quality, your dataset probably doesn't adequately match real-world data. You might have to retrain and retest against a new dataset. \nRetest on the same test set. The test results might have been an anomaly. \nAlthough retesting might yield slightly different results, this tactic probably isn't very helpful. \nHow many examples should the test set contain? \nEnough examples to yield a statistically significant test. \nYes. How many examples is that? You'll need to experiment. \nAt least 15% of the original dataset. \n15% may or may not be enough examples.\n| **Key terms:**\n|\n| - [Test set](/machine-learning/glossary#test-set)\n| - [Training set](/machine-learning/glossary#training-set)\n- [Validation set](/machine-learning/glossary#validation_set) \n[Help Center](https://support.google.com/machinelearningeducation)"]]