Model Pipeline - Handling categorical variables
This pipeline shows how we prepare data with categories, turn them into numbers, train a model, and check how well it learns to predict.
This pipeline shows how we prepare data with categories, turn them into numbers, train a model, and check how well it learns to predict.
Loss
0.7 |****
0.6 |***
0.5 |**
0.4 |*
0.3 |*
+-----
1 2 3 4 5 Epochs| Epoch | Loss ↓ | Accuracy ↑ | Observation |
|---|---|---|---|
| 1 | 0.65 | 0.60 | Model starts learning, loss is high, accuracy low |
| 2 | 0.50 | 0.72 | Loss decreases, accuracy improves |
| 3 | 0.40 | 0.80 | Model learns important patterns |
| 4 | 0.35 | 0.83 | Loss continues to decrease, accuracy rises |
| 5 | 0.30 | 0.85 | Training converges with good accuracy |
color?get_dummies() to convert categorical columns into one-hot encoded columns.pd.get_dummies(df['color']). Other options are not valid pandas methods.from sklearn.preprocessing import LabelEncoder le = LabelEncoder() df['size_encoded'] = le.fit_transform(df['size']) print(df['size_encoded'].tolist())
df['size'] contains ['small', 'medium', 'large', 'medium'], what will be the printed output?ValueError: Input contains NaN, infinity or a value too large for dtype('float64'). What is the most likely cause and fix?education_level having values: ['high school', 'bachelor', 'master', 'phd']. You want to use this feature in a regression model where order matters. Which encoding method should you choose and why?Pass the test and this pattern moves unknown