-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImproving_ML_Models.txt
121 lines (95 loc) · 6.1 KB
/
Improving_ML_Models.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
Improving Machine Learning Models
Initial Training:
The first model often underperforms.
Bias and Variance:
High Bias (Underfitting): Poor performance on both training and cross-validation sets. Example: A linear model on a complex dataset.
High Variance (Overfitting): Good performance on training but poor on cross-validation sets. Example: A high-degree polynomial model.
Balanced Model: Good performance on both training and cross-validation sets. Example: A quadratic polynomial model.
Diagnosing Issues:
High Bias: High error on the training set.
High Variance: Much higher error on the cross-validation set compared to the 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.
Use techniques like regularization to balance them.
Regularization and Lambda
Effect of Lambda:
High Lambda: Leads to high bias (underfitting) as model parameters are kept very small.
Low Lambda: Leads to high variance (overfitting) as the model fits the training data too closely.
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.
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.
Judging Bias and Variance with Concrete Numbers
Training and Cross-Validation Errors:
Training Error (J_train): Percentage of training set examples not predicted correctly.
Cross-Validation Error (J_cv): Percentage of cross-validation set examples not predicted 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.
High Variance: If J_cv is much higher than J_train.
Establishing Baseline Performance:
Compare J_train to human-level performance or a competing algorithm.
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.
Learning Curves
Cross-Validation Error (J_cv):
Decreases as the training set size (m_train) increases, indicating better model performance.
Training Error (J_train):
Initially low with few training examples, increases as the training set size increases.
High Bias (Underfitting):
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):
Training error is low, but cross-validation error is high.
Increasing the training set size can help reduce the cross-validation error and improve generalization.
In summary, understanding and addressing bias and variance, along with tuning regularization parameters like Lambda, are crucial for improving machine learning models. Learning curves provide valuable insights into the model's behavior and guide the next steps in model improvement.
----------------------------------------------
To diagnose whether your learning algorithm has high bias or high variance, you can look at the training error (J_train) and cross-validation error (J_cv), or plot a learning curve. This helps you decide the next steps to improve your model's performance. Here's a consolidated overview:
Diagnosing Bias and Variance
High Bias (Underfitting):
High error on both training and cross-validation sets.
Example: A linear model on a complex dataset.
High Variance (Overfitting):
Low training error but high cross-validation error.
Example: A high-degree polynomial model.
Strategies to Improve Model Performance
High Variance:
Get more training examples: Helps reduce overfitting.
Try a smaller set of features: Reduces model complexity.
Increase Lambda (regularization parameter): Adds regularization to smooth the model.
High Bias:
Add more features: Provides more information for the model.
Add polynomial features: Increases model complexity.
Decrease Lambda: Reduces regularization to allow more flexibility.
Practical Example: Predicting Housing Prices
Problem: The model makes large errors in predictions.
Possible Solutions:
High Variance: Get more training examples, reduce features, or increase Lambda.
High Bias: Add more features, add polynomial features, or decrease Lambda.
Key Takeaways
High Variance: Simplify the model or get more data.
High Bias: Make the model more complex or reduce regularization.
Regular Assessment: Continuously evaluate bias and variance to guide model adjustments.
Avoid Reducing Training Set Size: This can worsen cross-validation error and overall performance.
Understanding and systematically addressing bias and variance will help you make better decisions to improve your machine learning models. Regular practice and experience will deepen your understanding and effectiveness in applying these concepts.
---------------------------------------------------------------