Skip to content

Commit 81e4ce4

Browse files
committed
📝 : added all docs.
1 parent 690382c commit 81e4ce4

11 files changed

Lines changed: 95 additions & 3 deletions

File tree

Generalization/README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Generalization 👻
2+
3+
Generalization refers to a model's ability to perform well on new, unseen data. In linear regression, achieving good generalization means that the model captures the underlying trend in the data without overfitting or underfitting.
4+
5+
## Need to know for this section 👨🏽‍💻
6+
7+
### Bias and Variance
8+
9+
- <mark>**_Bias_**:</mark>
10+
11+
Bias is the error introduced by approximating a real-world problem (which may be complex) by a simplified model. In linear regression, high bias often occurs when the model is too simple to capture the underlying patterns in the data.
12+
13+
> **_High bias_** can lead to underfitting, where the model fails to capture the underlying trend and performs poorly on both training and test data.
14+
15+
- <mark>**_Variance_**:</mark>
16+
17+
Variance is the error introduced by the model’s sensitivity to fluctuations in the training data. High variance occurs when the model is too complex and learns not only the underlying patterns but also the noise in the training data.
18+
19+
> **_High variance_** can lead to overfitting, where the model performs very well on training data but poorly on test data due to its excessive complexity.
20+
21+
</br>
22+
23+
![generalization](./assets/genaralize.png)
24+
</br>
25+
26+
> For the left img is "high bias but low variance". On the other hand, the right img is "low bias and high varaince". Which both cause the overfitting and underfitting!
27+
28+
### Overfitting vs. Underfitting
29+
30+
- Overfitting:
31+
32+
Occurs when a model learns the noise in the training data rather than the actual signal. This results in excellent performance on training data but poor performance on new, unseen data.
33+
34+
<mark>High variance, low training error, high test error. (low bias)</mark>
35+
36+
- Underfitting:
37+
38+
Occurs when a model is too simplistic to capture the underlying patterns in the data. This results in poor performance on both training and test data.
39+
40+
<mark>High bias, high training error, high test error.</mark>
41+
42+
### Goal Representation
43+
44+
Bias vs. Variance Trade-off:
45+
46+
- **_High Bias (Underfitting)_** ⟶ Simple Model ⟶ High Training Error, High Test Error
47+
- **_Low Bias, Low Variance_** ⟶ Optimal Model ⟶ Low Training Error, Low Test Error
48+
- **_High Variance (Overfitting)_** ⟶ Complex Model ⟶ Low Training Error, High Test Error
49+
50+
> Training error is E in and Testing error is E out
51+
52+
### Note 🚨
53+
54+
We can visualize overfitting and underfitting by making a learning curve. You can follow the link https://github.com/Kariusdi/Machine-Learning-Class67/tree/main/LearningCurve.
506 KB
Loading
Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,34 @@
1-
Use jupyternotebook
1+
# Nested Cross-Validation 🧵
2+
3+
Nested cross-validation is a robust technique used to evaluate the performance of a machine learning model and to tune its hyperparameters. It involves two nested loops of cross-validation to avoid overfitting and to ensure that hyperparameter tuning does not bias the model evaluation.
4+
5+
![nested](./assets/nested.png)
6+
</br>
7+
8+
> We use Jupytor notebook for this section
9+
10+
## Need to know for this section 👨🏽‍💻
11+
12+
### How It Works
13+
14+
1. <mark>**_Outer Cross-Validation Loop:_**</mark>
15+
16+
- Purpose: Estimates the generalization performance of the model.
17+
18+
- Process: The dataset is divided into several folds (e.g., 5 or 10). For each iteration, one fold is held out as the test set, while the remaining folds are used for training and hyperparameter tuning.
19+
20+
2. <mark>**_Inner Cross-Validation Loop:_**</mark>
21+
22+
- Purpose: Selects the best hyperparameters for the model.
23+
24+
- Process: Within each training set from the outer loop, the data is further split into training and validation sets. The model is trained on the training set with different hyperparameters and evaluated on the validation set to find the optimal hyperparameters.
25+
26+
### Benefits
27+
28+
- **Unbiased Evaluation:** Provides an unbiased estimate of the model's performance by ensuring that hyperparameter tuning does not influence the test set performance.
29+
30+
- **Robustness:** Helps in selecting the best model and its hyperparameters while mitigating overfitting.
31+
32+
### Example Use
33+
34+
Nested cross-validation is particularly useful for models with many hyperparameters or when working with small datasets, as it provides a reliable estimate of model performance and parameter settings.
334 KB
Loading

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This is for ML class as a senior year, 2567.
77
- [Linear Regression](https://github.com/Kariusdi/Machine-Learning-Class67/tree/main/Linear-Regression)
88
- [Performance Estimation](https://github.com/Kariusdi/Machine-Learning-Class67/tree/main/Performance-Estimation)
99
- [Experiments with Python](https://github.com/Kariusdi/Machine-Learning-Class67/tree/main/Performance-Estimation/Experiments-python)
10-
- [Nested Cross Validation](https://github.com/Kariusdi/Machine-Learning-Class67/tree/main/Performance-Estimation/Nested_CV)
10+
- [Nested Cross Validation](https://github.com/Kariusdi/Machine-Learning-Class67/tree/main/Performance-Estimation/Nested-CrossValidation)
1111
- [Generalization](https://github.com/Kariusdi/Machine-Learning-Class67/tree/main/Generalization)
1212
- [Constant Model](https://github.com/Kariusdi/Machine-Learning-Class/tree/main/Generalization/ConstantModel)
1313
- [Linear Model](https://github.com/Kariusdi/Machine-Learning-Class/tree/main/Generalization/LinearModel)

Regularization/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,8 @@ In linear regression, the goal is to find the best-fitting line (or hyperplane i
9090
### Summary 💼
9191

9292
In summary, regularization helps control model complexity, improves generalization, and enhances the performance of linear regression models by adding a penalty for large coefficients.
93+
94+
> Please follow this link, it's very helpful.
95+
96+
https://youtu.be/Xm2C_gTAl8c?si=kVIxoW-fcGWpWEi3
97+
https://www.youtube.com/watch?v=Q81RR3yKn30
File renamed without changes.
File renamed without changes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def plot_rmse_vs_alpha(alphas, train_rmse, test_rmse):
4242
plt.tight_layout()
4343
plt.show()
4444

45-
X_train, Y_train, X_test, Y_test = import_csv("Regularization/dataset/HeightWeight.csv")
45+
X_train, Y_train, X_test, Y_test = import_csv("../dataset/HeightWeight.csv")
4646
#X_train, Y_train, X_test, Y_test = generate_sin()
4747

4848
alphas = np.arange(1, 100000, 100)

0 commit comments

Comments
 (0)