32. Features and Labels in Machine Learning
32.4 Building a Tiny Feature Table in pandas
Why. Your hands need one tiny pandas build before sklearn models arrive.
What. Build X and y from a clean fictional table.
How.
import pandas as pd
raw = pd.DataFrame({
"order_id": ["BLK-1", "BLK-2", "BLK-3", "BLK-4", "BLK-5", "BLK-6"],
"city": ["Pune", "Solapur", "Pune", "Nashik", "Kolhapur", "Nagpur"],
"items": [2, 6, 3, 5, 4, 8],
"distance_km": [1.1, 7.5, 2.0, 3.4, 4.2, 5.1],
"rain_mm": [0, 10, 0, 0, 2, 0],
"was_late": [0, 1, 0, 0, 1, 1],
})
feature_cols = ["items", "distance_km", "rain_mm"]
X = raw[feature_cols].copy()
y = raw["was_late"].copy()
print(X)
print(y.value_counts())
What you should see. X has only allowed inputs. y is the 0/1 label. order_id and city stayed out for this tiny numeric-only demo (city can return later as a category feature).
Ravindra Bagale's Tip
feature_cols list ek variable madhe theva. Mag train_test_split. Mag model. Same list reuse — copy-paste columns chuk reduce hote.