Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Bài trước đã giới thiệu mô hình sau đây, mô hình này đã phân loại sai nhiều cây trong tập dữ liệu kiểm thử:
Hình 16. Mô hình phức tạp hoạt động không đúng cách trong bài trước.
Mô hình trước đó chứa nhiều hình dạng phức tạp. Mô hình đơn giản hơn có xử lý dữ liệu mới tốt hơn không? Giả sử bạn thay thế mô hình phức tạp bằng một mô hình đơn giản đến mức nực cười – một đường thẳng.
Hình 17. Một mô hình đơn giản hơn nhiều.
Mô hình đơn giản khái quát tốt hơn mô hình phức tạp trên dữ liệu mới. Tức là mô hình đơn giản đã đưa ra dự đoán tốt hơn trên tập dữ liệu kiểm thử so với mô hình phức tạp.
Sự đơn giản đã đánh bại sự phức tạp từ lâu. Trên thực tế, việc ưu tiên sự đơn giản đã có từ thời Hy Lạp cổ đại. Nhiều thế kỷ sau, một tu sĩ thế kỷ 14 tên là William of Occam đã chính thức hoá lựa chọn ưu tiên về sự đơn giản trong một triết lý được gọi là lưỡi dao Occam. Triết lý này vẫn là một nguyên tắc cơ bản quan trọng của nhiều ngành khoa học, bao gồm cả học máy.
Bài tập: Kiểm tra mức độ hiểu biết
Bạn đang phát triển một phương trình vật lý. Công thức nào sau đây phù hợp hơn với quy tắc Lưỡi dao Occam?
Một công thức có ba biến.
Ba biến phù hợp với nguyên tắc Occam hơn 12 biến.
Một công thức có 12 biến.
12 biến có vẻ quá phức tạp, phải không? Hai công thức vật lý nổi tiếng nhất mọi thời đại (F=ma và E=mc2) chỉ liên quan đến 3 biến.
Bạn đang làm việc trên một dự án học máy hoàn toàn mới và sắp chọn các tính năng đầu tiên. Bạn nên chọn bao nhiêu tính năng?
Chọn 1–3 đặc điểm có vẻ như có khả năng dự đoán mạnh.
Tốt nhất là quy trình thu thập dữ liệu của bạn chỉ nên bắt đầu với một hoặc hai tính năng. Điều này sẽ giúp bạn xác nhận rằng mô hình học máy hoạt động như dự kiến. Ngoài ra, khi tạo đường cơ sở từ một vài tính năng, bạn sẽ cảm thấy mình đang tiến bộ!
Chọn 4 đến 6 đặc điểm có vẻ như có khả năng dự đoán mạnh mẽ.
Cuối cùng, bạn có thể sử dụng nhiều tính năng như vậy, nhưng tốt hơn hết là bạn nên bắt đầu với ít tính năng hơn. Ít tính năng hơn thường đồng nghĩa với ít chức năng không cần thiết hơn.
Chọn nhiều đặc điểm nhất có thể để bạn có thể bắt đầu quan sát xem đặc điểm nào có khả năng dự đoán mạnh nhất.
Bắt đầu từ quy mô nhỏ. Mỗi tính năng mới sẽ thêm một phương diện mới vào tập dữ liệu đào tạo. Khi số chiều tăng lên, dung lượng của không gian sẽ tăng lên nhanh chóng khiến dữ liệu huấn luyện có sẵn trở nên thưa thớt. Dữ liệu của bạn càng thưa thớt thì mô hình càng khó tìm hiểu mối quan hệ giữa các đặc điểm thực sự quan trọng và nhãn. Hiện tượng này được gọi là "lời nguyền về số chiều".
Điều hoà
Các mô hình học máy phải đồng thời đáp ứng hai mục tiêu xung đột:
Phù hợp với dữ liệu.
Điều chỉnh dữ liệu sao cho đơn giản nhất có thể.
Một phương pháp để giữ cho mô hình đơn giản là phạt các mô hình phức tạp; tức là buộc mô hình trở nên đơn giản hơn trong quá trình huấn luyện. Việc phạt các mô hình phức tạp là một hình thức điều chỉnh.
Mất dữ liệu và độ phức tạp
Cho đến nay, khoá học này đã đề xuất rằng mục tiêu duy nhất khi huấn luyện là giảm thiểu tổn thất; tức là:
$$\text{minimize(loss)}$$
Như bạn đã thấy, các mô hình chỉ tập trung vào việc giảm thiểu tổn thất có xu hướng phù hợp quá mức. Thuật toán tối ưu hoá hoạt động huấn luyện tốt hơn sẽ giảm thiểu một số tổ hợp tổn thất và độ phức tạp:
$$\text{minimize(loss + complexity)}$$
Thật không may, tổn thất và độ phức tạp thường có mối quan hệ nghịch. Khi độ phức tạp tăng lên, tổn thất sẽ giảm. Khi độ phức tạp giảm, tổn thất sẽ tăng lên. Bạn nên tìm một điểm trung gian hợp lý để mô hình đưa ra dự đoán chính xác về cả dữ liệu huấn luyện và dữ liệu thực tế. Tức là mô hình của bạn phải tìm được một điểm dung hoà hợp lý giữa tổn thất và độ phức tạp.
Độ phức tạp là gì?
Bạn đã thấy một vài cách định lượng tổn thất. Bạn sẽ định lượng độ phức tạp bằng cách nào? Hãy bắt đầu khám phá thông qua bài tập sau:
Bài tập: Kiểm tra trực giác của bạn
Cho đến nay, chúng ta vẫn chưa hiểu rõ về khái niệm độ phức tạp. Theo bạn, ý tưởng nào sau đây sẽ là chỉ số độ phức tạp hợp lý?
Độ phức tạp là một hàm của trọng số của mô hình.
Có, đây là một cách để đo lường độ phức tạp của một số mô hình. Chỉ số này được gọi là điều hoà L1.
Độ phức tạp là hàm của bình phương trọng số của mô hình.
Có, bạn có thể đo lường độ phức tạp của một số mô hình theo cách này. Chỉ số này được gọi là điều hoà L2.
Độ phức tạp là một hàm của các độ lệch của tất cả các tính năng trong mô hình.
[null,null,["Cập nhật lần gần đây nhất: 2024-11-14 UTC."],[[["\u003cp\u003eSimpler models often generalize better to new data than complex models, even if they perform slightly worse on training data.\u003c/p\u003e\n"],["\u003cp\u003eOccam's Razor favors simpler explanations and models, prioritizing them over more complex ones.\u003c/p\u003e\n"],["\u003cp\u003eRegularization techniques help prevent overfitting by penalizing model complexity during training.\u003c/p\u003e\n"],["\u003cp\u003eModel training aims to minimize both loss (errors on training data) and complexity for optimal performance on new data.\u003c/p\u003e\n"],["\u003cp\u003eModel complexity can be quantified using functions of model weights, like L1 and L2 regularization.\u003c/p\u003e\n"]]],[],null,["The previous unit introduced the following model, which miscategorized a lot\nof trees in the test set:\n**Figure 16.** The misbehaving complex model from the previous unit.\n\nThe preceding model contains a lot of complex shapes. Would a simpler\nmodel handle new data better? Suppose you replace the complex model with\na ridiculously simple model--a straight line.\n**Figure 17.** A much simpler model.\n\nThe simple model generalizes better than the complex model on new data. That is,\nthe simple model made better predictions on the test set than the complex model.\n\nSimplicity has been beating complexity for a long time. In fact, the\npreference for simplicity dates back to ancient Greece. Centuries later,\na fourteenth-century friar named William of Occam formalized the preference\nfor simplicity in a philosophy known as [Occam's\nrazor](https://wikipedia.org/wiki/Occam%27s_razor). This philosophy\nremains an essential underlying principle of many sciences, including\nmachine learning.\n| **Note:** Complex models typically outperform simple models on the training set. However, simple models typically outperform complex models on the test set (which is more important).\n\nExercises: Check your understanding \nYou are developing a physics equation. Which of the following formulas conform more closely to Occam's Razor? \nA formula with three variables. \nThree variables is more Occam-friendly than twelve variables. \nA formula with twelve variables. \nTwelve variables seems overly complicated, doesn't it? The two most famous physics formulas of all time (F=ma and E=mc^2^) each involve only three variables. \nYou're on a brand-new machine learning project, about to select your first features. How many features should you pick? \nPick 1--3 features that seem to have strong predictive power. \nIt's best for your data collection pipeline to start with only one or two features. This will help you confirm that the ML model works as intended. Also, when you build a baseline from a couple of features, you'll feel like you're making progress! \nPick 4--6 features that seem to have strong predictive power. \nYou might eventually use this many features, but it's still better to start with fewer. Fewer features usually means fewer unnecessary complications. \nPick as many features as you can, so you can start observing which features have the strongest predictive power. \nStart smaller. Every new feature adds a new dimension to your training dataset. When the dimensionality increases, the volume of the space increases so fast that the available training data become sparse. The sparser your data, the harder it is for a model to learn the relationship between the features that actually matter and the label. This phenomenon is called \"the curse of dimensionality.\"\n\nRegularization\n\nMachine learning models must simultaneously meet two conflicting goals:\n\n- Fit data well.\n- Fit data as simply as possible.\n\nOne approach to keeping a model simple is to penalize complex models; that is,\nto force the model to become simpler during training. Penalizing complex\nmodels is one form of **regularization**.\n| **A regularization analogy:** Suppose every student in a lecture hall had a little buzzer that emitted a sound that annoyed the professor. Students would press the buzzer whenever the professor's lecture became too complicated. Annoyed, the professor would be forced to simplify the lecture. The professor would complain, \"When I simplify, I'm not being precise enough.\" The students would counter with, \"The only goal is to explain it simply enough that I understand it.\" Gradually, the buzzers would train the professor to give an appropriately simple lecture, even if the simpler lecture isn't as sufficiently precise.\n\nLoss and complexity\n\nSo far, this course has suggested that the only goal when training was to\nminimize loss; that is: \n$$\\\\text{minimize(loss)}$$\n\nAs you've seen, models focused solely on minimizing loss tend to overfit.\nA better training optimization algorithm minimizes some combination of\nloss and complexity: \n$$\\\\text{minimize(loss + complexity)}$$\n\nUnfortunately, loss and complexity are typically inversely related. As\ncomplexity increases, loss decreases. As complexity decreases, loss increases.\nYou should find a reasonable middle ground where the model makes good\npredictions on both the training data and real-world data.\nThat is, your model should find a reasonable compromise\nbetween loss and complexity.\n\nWhat is complexity?\n\nYou've already seen a few different ways of quantifying loss. How would\nyou quantify complexity? Start your exploration through the following exercise:\n\nExercise: Check your intuition \nSo far, we've been pretty vague about what *complexity* actually is. Which of the following ideas do you think would be reasonable complexity metrics? \nComplexity is a function of the model's weights. \nYes, this is one way to measure some models' complexity. This metric is called [**L~1~ regularization.**](/machine-learning/glossary#L1_regularization) \nComplexity is a function of the square of the model's weights. \nYes, you can measure some models' complexity this way. This metric is called [**L~2~ regularization**](/machine-learning/glossary#L2_regularization). \nComplexity is a function of the biases of all the features in the model. \nBias doesn't measure complexity.\n| **Key terms:**\n|\n| - [L~1~ regularization](/machine-learning/glossary#L1_regularization)\n| - [L~2~ regularization](/machine-learning/glossary#L2_regularization)\n- [Regularization](/machine-learning/glossary#regularization) \n[Help Center](https://support.google.com/machinelearningeducation)"]]