-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbias_and_variance.txt
125 lines (94 loc) · 7.84 KB
/
bias_and_variance.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
When developing a machine learning system, the initial model often doesn't perform as expected. Improving its performance involves understanding and addressing bias and variance. Here's a consolidated overview:
Initial Training: The first model usually underperforms.
Bias and Variance: Key concepts to diagnose and improve model performance.
High Bias (Underfitting): Model performs poorly on both training and cross-validation sets. Example: A linear model on a complex dataset.
High Variance (Overfitting): Model performs well on training but poorly on cross-validation sets. Example: A high-degree polynomial model.
Balanced Model: Performs well on both training and cross-validation sets. Example: A quadratic polynomial model.
Diagnosing Issues:
High Bias: High error on training set.
High Variance: Much higher error on cross-validation set compared to training set.
Visualizing Performance:
Training Error (J_train): Decreases with more complex models.
Cross-Validation Error (J_cv): Forms a U-shape; high for both very simple and very complex models, lowest for a balanced model.
Simultaneous High Bias and Variance: Rare but possible, especially in complex models like neural networks.
Improvement Strategy: Regularly assess bias and variance to guide model adjustments and use techniques like regularization to balance them.
Understanding these concepts helps in systematically improving machine learning models.
Lambda:
Check how, Lambda, affects the bias and variance of a learning algorithm, and how to choose an optimal value for Lambda using cross-validation. Here's a consolidated overview:
Regularization and Lambda:
High Lambda: Leads to high bias (underfitting) as the model parameters are kept very small, resulting in poor performance on the training set.
Low Lambda: Leads to high variance (overfitting) as the model fits the training data too closely, performing poorly on the cross-validation set.
Optimal Lambda: A balanced value that minimizes both training and cross-validation errors.
Choosing Lambda:
Use cross-validation to test different values of Lambda.
Evaluate the cross-validation error for each Lambda.
Select the Lambda that results in the lowest cross-validation error.
Error Analysis:
Training Error (J_train): Increases with higher Lambda due to stronger regularization.
Cross-Validation Error (J_cv): Forms a U-shape; high for both very low and very high Lambda values, lowest at an optimal intermediate value.
Visual Comparison:
The relationship between Lambda and errors is similar to the relationship between polynomial degree and errors, but mirrored. High bias is on the right for Lambda and on the left for polynomial degree.
Practical Application:
Regularly assess and adjust Lambda to balance bias and variance.
Use cross-validation to find the optimal regularization parameter for your specific application.
Understanding and tuning Lambda helps in achieving a well-performing machine learning model by balancing bias and variance effectively.
To judge if a learning algorithm has high bias or high variance, we can look at concrete numbers for training error (J_train) and cross-validation error (J_cv). Here's a consolidated overview using speech recognition as an example:
Training and Cross-Validation Errors:
Training Error (J_train): Percentage of training set audio clips not transcribed correctly.
Cross-Validation Error (J_cv): Percentage of cross-validation set audio clips not transcribed correctly.
Example:
J_train: 10.8%
J_cv: 14.8%
Human-Level Performance: 10.6%
Analysis:
High Bias: If J_train is much higher than human-level performance (baseline), the algorithm has high bias.
High Variance: If J_cv is much higher than J_train, the algorithm has high variance.
Establishing Baseline Performance:
Compare J_train to human-level performance or a competing algorithm to determine if the training error is high.
Use the gap between J_train and J_cv to assess variance.
Concrete Examples:
High Variance: J_train (10.8%) is close to human-level (10.6%), but J_cv (14.8%) is much higher.
High Bias: If J_train (15%) is much higher than human-level (10.6%) and J_cv (16%) is only slightly higher than J_train.
Simultaneous High Bias and Variance:
Large gaps between baseline and J_train, and between J_train and J_cv indicate both high bias and high variance.
Summary:
High Bias: Large gap between baseline and J_train.
High Variance: Large gap between J_train and J_cv.
Establishing a baseline helps in accurately judging bias and variance.
Understanding these concepts helps in diagnosing and improving the performance of machine learning algorithms.
Learning curves help understand how a learning algorithm performs as it gains more experience, typically measured by the number of training examples. When plotting learning curves for a model fitting a second-order polynomial (quadratic function), we observe the following:
Cross-Validation Error (J_cv):
As the training set size (m_train) increases, the cross-validation error generally decreases, indicating better model performance.
Training Error (J_train):
Initially, with very few training examples, the training error is low or zero because the model can fit the data perfectly.
As the training set size increases, the training error increases because it becomes harder to fit all examples perfectly.
High Bias (Underfitting):
Example: Fitting a linear function to data.
Both training and cross-validation errors are high and flatten out as the training set size increases.
Adding more training data does not significantly improve performance.
High Variance (Overfitting):
Example: Fitting a high-order polynomial with low regularization.
Training error is low, but cross-validation error is high, indicating overfitting.
Increasing the training set size can help reduce the cross-validation error and improve generalization.
In summary, learning curves can diagnose whether a model suffers from high bias or high variance. For high bias, more complex models or features are needed. For high variance, increasing the training set size can help improve performance. Plotting learning curves, though computationally expensive, provides valuable insights into the model's behavior and guides the next steps in model improvement.
Bias and Variance in Machine Learning
Bias and Variance Tradeoff:
High Bias: Simple models (e.g., linear models) may underfit the data, leading to high bias.
High Variance: Complex models (e.g., high-order polynomials) may overfit the data, leading to high variance.
Tradeoff: Traditionally, machine learning engineers balanced model complexity to minimize both bias and variance.
Neural Networks and the Tradeoff:
Large Neural Networks: When trained on small to moderate datasets, they are low bias machines, meaning they can fit the training data well.
Recipe for Model Improvement:
Train on Training Set: Check if the model performs well on the training set.
High Bias: If performance is poor, increase the model size (more layers/units).
High Variance: If the model performs well on the training set but poorly on the validation set, gather more data.
Regularization:
Purpose: Helps prevent overfitting in large neural networks.
Implementation: Add regularization terms to the cost function (e.g., L2 regularization).
Practical Considerations:
Computational Cost: Larger networks require more computational resources.
Data Availability: Sometimes, obtaining more data is challenging.
Modern Approach:
Focus on Variance: With large neural networks, the primary challenge often shifts to managing variance rather than bias.
Regularization and Data: Proper regularization and sufficient data are key to leveraging large neural networks effectively.
This approach has significantly influenced the rise of deep learning, allowing for better performance in various applications by effectively managing bias and variance.