Model Pipeline - Overfitting and underfitting
This pipeline shows how a model learns from data and what happens when it learns too little (underfitting) or too much (overfitting). It helps us understand the balance needed for good predictions.
This pipeline shows how a model learns from data and what happens when it learns too little (underfitting) or too much (overfitting). It helps us understand the balance needed for good predictions.
Epoch 1: ********** (loss=0.9) Epoch 5: ******* (loss=0.6) Epoch 10: **** (loss=0.4) Epoch 15: *** (loss=0.3) Epoch 20: ** (loss=0.25)
| Epoch | Loss ↓ | Accuracy ↑ | Observation |
|---|---|---|---|
| 1 | 0.9 | 0.40 | Model starts learning, loss high, accuracy low |
| 5 | 0.6 | 0.65 | Model improves, loss decreases, accuracy increases |
| 10 | 0.4 | 0.80 | Good fit, model learns well |
| 15 | 0.3 | 0.90 | Model fits training data very well |
| 20 | 0.25 | 0.95 | Model may start overfitting, very low loss on training |
overfitting mean in machine learning?underfitting in a model?from sklearn.tree import DecisionTreeClassifier from sklearn.datasets import load_iris from sklearn.model_selection import train_test_split X, y = load_iris(return_X_y=True) X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42) model = DecisionTreeClassifier(max_depth=1) model.fit(X_train, y_train) train_score = model.score(X_train, y_train) test_score = model.score(X_test, y_test) print(round(train_score, 2), round(test_score, 2))What is the likely output?
from sklearn.tree import DecisionTreeClassifier from sklearn.datasets import load_iris from sklearn.model_selection import train_test_split X, y = load_iris(return_X_y=True) X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42) model = DecisionTreeClassifier(max_depth=10) model.fit(X_train, y_train) print(model.score(X_train, y_train)) print(model.score(X_test, y_test)) # To reduce overfitting, we set max_depth=1 model.max_depth = 1 print(model.score(X_train, y_train)) print(model.score(X_test, y_test))What is the error in this approach?
Pass the test and this pattern moves unknown