You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source/content/overview/overfitting.rst
+81-7Lines changed: 81 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -9,26 +9,100 @@ Overfitting and Underfitting
9
9
----------------------------
10
10
Overview
11
11
----------------------------
12
-
When using machine learning, there are many ways to go wrong. Some of the most common issues in machine learning are **overfitting** and **underfitting**. To understand these concepts, let's imagine a machine learning model that is trying to learn to classify numbers, and has access to a training set of data and a testing set of data. Be sure to **follow along with the sample code** courtesy of scikit-learn.org
12
+
When using machine learning, there are many ways to go wrong.
13
+
Some of the most common issues in machine learning are **overfitting** and **underfitting**.
14
+
To understand these concepts, let's imagine a machine learning model that is
15
+
trying to learn to classify numbers, and has access to a training set of data and a testing set of data.
13
16
14
17
----------------------------
15
18
Overfitting
16
19
----------------------------
17
20
18
-
A model suffers from **Overfitting** when it has learned too much from the training data, and does not perform well in practice as a result. This is usually caused by the model having too much exposure to the training data. For the number classification example, if the model is overfit in this way, it may be picking up on tiny details that are misleading, like stray marks as an indication of a specific number.
21
+
A model suffers from **Overfitting** when it has learned too much from the
22
+
training data, and does not perform well in practice as a result.
23
+
This is usually caused by the model having too much exposure to the training data.
24
+
For the number classification example, if the model is overfit in this way, it
25
+
may be picking up on tiny details that are misleading, like stray marks as an indication of a specific number.
19
26
20
-
The estimate looks pretty good when you look at the middle of the graph, but the edges have large error. In practice, this error isn't always at edge cases and can pop up anywhere. The noise in training can cause the error seen in the graph
27
+
The estimate looks pretty good when you look at the middle of the graph, but the edges have large error.
28
+
In practice, this error isn't always at edge cases and can pop up anywhere.
29
+
The noise in training can cause error as seen in the graph below.
30
+
31
+
.. figure:: _img/Overfit_small.png
32
+
:scale:10 %
33
+
:alt:Overfit
34
+
(Created using https://www.desmos.com/calculator/dffnj2jbow)
35
+
36
+
In this example, the data is overfit by a polynomial degree.
37
+
The points indicated are true to the function y = x^2, but does not approximate the function well outside of those points.
21
38
22
39
----------------------------
23
40
Underfitting
24
41
----------------------------
25
42
26
-
A model suffers from **Underfitting** when it has not learned enough from the training data, and does not perform well in practice as a result. As a direct contrast to the previous idea, this issue is caused by not letting the model learn enough from training data. In the number classification example, if the training set is too small or the model has not had enough attempts to learn from it, then it will not be able to pick out key features of the numbers.
43
+
A model suffers from **Underfitting** when it has not learned enough from the
44
+
training data, and does not perform well in practice as a result.
45
+
As a direct contrast to the previous idea, this issue is caused by not letting
46
+
the model learn enough from training data.
47
+
In the number classification example, if the training set is too small or the
48
+
model has not had enough attempts to learn from it, then it will not be able to pick out key features of the numbers.
49
+
50
+
51
+
The issue with this estimate is clear to the human eye, the model should be
52
+
nonlinear, and is instead just a simple line.
53
+
In machine learning, this could be a result of underfitting, the model has not
54
+
had enough exposure to training data to adapt to it, and is currently in a simple state.
55
+
56
+
.. figure:: _img/Underfit.PNG
57
+
:scale:50 %
58
+
:alt:Underfit
59
+
(Created using Wolfram Alpha)
60
+
61
+
----------------------------
62
+
Motivation
63
+
----------------------------
64
+
65
+
Finding a good fit is one of the central problems in machine learning.
66
+
Gaining a good grasp of how to avoid fitting problems before even worrying
67
+
about specific methods can keep models on track.
68
+
The mindset of hunting for a good fit, rather than throwing more learning
69
+
time at a model is very important to have.
27
70
71
+
----------------------------
72
+
Code
73
+
----------------------------
74
+
75
+
The example code for overfitting shows some basic examples based in polynomial
76
+
interpolation, trying to find the equation of a graph.
77
+
The overfitting.py_ file, you can see that there is a true function being
78
+
modeled, as well as some estimates that are shown to not be accurate.
The estimates are representations of overfitting and underfitting.
83
+
For overfitting, a higher degree polynomial is used (x cubed instead of squared).
84
+
While the data is relatively close for the chosen points, there are some artifacts outside of them.
85
+
The example of underfitting, however, does not even achieve accuracy at many of the points.
86
+
Underfitting is similar to having a linear model when trying to model a quadratic function.
87
+
The model does well on the point(s) it trained on, in this case the point used
88
+
for the linear estimate, but poorly otherwise.
28
89
29
-
The issue with this estimate is clear to the human eye, the model should be nonlinear, and is instead just a simple line. In machine learning, this could be a result of underfitting, the model has not had enough exposure to training data to adapt to it, and is currently in a simple state.
30
90
31
91
----------------------------
32
-
How to avoid overfitting
92
+
Conclusion
33
93
----------------------------
34
-
A key idea in avoiding overfitting issues in machine learning is to maintain a **validation set**. This set is used for training purposes, but most importantly the model **does not learn from it**. So, the model first learns from the **training set**, then checks its knowledge on a completely different **validation set**. When it performs well enough on the **validation set**, we can be more confident that it is not overfit to the training data than if we just looked at training results.
94
+
95
+
Check out the cross-validation and regularization sections for information on
96
+
how to avoid overfitting in machine learning models.
97
+
Ideally, a good fit looks something like this:
98
+
99
+
.. figure:: _img/GoodFit.PNG
100
+
:scale:50 %
101
+
:alt:Underfit
102
+
(Created using Wolfram Alpha)
103
+
104
+
105
+
When using machine learning in any capacity, issues such as overfitting
106
+
frequently come up, and having a grasp of the concept is very important.
107
+
The modules in this section are among the most important in the whole repository,
108
+
since regardless of the implementation, machine learning always includes these fundamentals.
0 commit comments