Ravindra BagaleCourses & study guides English Track your progress

40. Machine Learning साठी Data Preprocessing (Missing Values, Scaling, Encoding)

Data Science

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 ची नावे सांगा

  1. Missing values → impute किंवा drop.
  2. Scaling → columns समान numeric range वर आणा (उदा. StandardScaler).
  3. 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.