32. Machine Learning मध्ये Features आणि Labels
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.
Ravindra Bagale's Tip – मराठी
तुमच्या feature columns ची नावं feature_cols सारख्या एका list मध्ये, एकाच variable मध्ये ठेवा. हीच list train_test_split साठी, model train करण्यासाठी आणि predictions करण्यासाठी वापरा. एकच list पुन्हा पुन्हा वापरली की column नावांच्या copy-paste चुका टळतात.
Ravindra Bagale's Tip – हिंदी
अपने feature columns के नाम feature_cols जैसी एक list में, एक ही variable में रखो. यही list train_test_split के लिए, model train करने के लिए और predictions के लिए इस्तेमाल करो. जब तुम एक ही list बार-बार इस्तेमाल करते हो, तो column नामों की copy-paste गलतियाँ नहीं होतीं.