40. Machine Learning साठी Data Preprocessing (Missing Values, Scaling, Encoding)
40.1 Models आधी Preprocessing का
का गरजेचे आहे. खऱ्या India tables मध्ये रिकाम्या cells, वेगवेगळ्या scales वर ₹ आणि kg, आणि text म्हणून city names असतात. LogisticRegression आणि nets सारख्या models ला नीट numbers हवेत. Preprocessing ही tidy-up पायरी आहे.
हे काय आहे. Fit आधी अनेकदा: missing values भरून किंवा काढून टाका, numeric columns scale करा, आणि categories numbers मध्ये encode करा. फक्त training statistics वापरा — scaler सेट करण्यासाठी test set कधीही peek करू नका.
कसे करायचे.
तीन jobs ची नावे सांगा
- Missing values → impute किंवा drop.
- Scaling → columns समान numeric range वर आणा (उदा. StandardScaler).
- Encoding → “Pune” / “Nashik” model वाचेल अशा columns मध्ये बदला.
import pandas as pd
raw = pd.DataFrame({
"city": ["Pune", "Nashik", None, "Pune"],
"litres": [120.0, None, 90.0, 150.0],
"distance_km": [12, 35, 40, 8],
})
print(raw)
print("Problem: NaNs + text city + mixed scales.")
Ravindra Bagale's Tip
Think of preprocessing as washing and cutting vegetables before you cook. In the same way, clean and prepare your data first, and never put raw, messy data straight into the model.
Ravindra Bagale's Tip – मराठी
Preprocessing म्हणजे स्वयंपाक करण्याआधी भाज्या धुणे आणि चिरणे. त्याचप्रमाणे आधी data साफ करून तयार करा, आणि कच्चा, गोंधळलेला data थेट model मध्ये कधीही टाकू नका.
Ravindra Bagale's Tip – हिंदी
Preprocessing को ऐसे समझो जैसे खाना बनाने से पहले सब्ज़ी धोना और काटना. उसी तरह पहले data को साफ़ करके तैयार करो, और कच्चा, गड़बड़ data सीधे model में कभी मत डालो.