Ravindra BagaleCourses & study guides English Track your progress

32. Machine Learning मध्ये Features आणि Labels

Data Science

32.4 pandas मध्ये छोटी Feature Table

का गरजेचे आहे. sklearn models येण्यापूर्वी आपण pandas मध्ये एक छोटी feature table तयार करून पाहतो.

हे काय आहे. Clean काल्पनिक table मधून X आणि y तयार करा.

कसे करायचे.

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())

तुम्हाला काय दिसायला हवे. X मध्ये फक्त परवानगी असलेले inputs. y हा 0/1 label आहे. या छोट्या numeric-only demo मध्ये order_id आणि city बाहेर ठेवले (city नंतर category feature म्हणून येऊ शकते).

Ravindra Bagale's Tip

Write your feature column names once, in one list such as feature_cols, and store it in a single variable. Use this same list for train_test_split, for training the model and for making predictions. When you reuse one list, you avoid copy-paste mistakes in column names.