34. Logistic Regression ने Python मध्ये Classification
34.4 Thresholds आणि Class-Balance चुका
का गरजेचे आहे. Labels उलटे, classes छोट्या, किंवा encoding शिवाय raw city text दिल्यास classification notebooks शांतपणे अपयशी ठरतात.
हे काय आहे. लक्ष द्या: majority class predict करून success म्हणणे; rare fraud labels वर stratify skip; 0/1 y वर LinearRegression; city names ला बहुतेक sklearn models आधी encoding लागते हे विसरणे.
कसे करायचे.
त्वरित रक्षक
- Split आधी
y.value_counts()print करा. - Binary labels साठी शक्य असल्यास
stratify=yवापरा. - Features numeric ठेवा (किंवा categories स्पष्ट encode करा).
- 95% “not churn” data वर फक्त accuracy साजरी करू नका — Chapter 37.
print(y.value_counts())
# If one class has only 1–2 rows, get more data before trusting metrics.
Ravindra Bagale's Tip
A model that predicts 0 for every row can still show high accuracy, but such a model is useless. This happens when one class is much bigger than the other. Always check the class balance first, so you know what score a simple guess would get.
Ravindra Bagale's Tip – मराठी
प्रत्येक row साठी 0 predict करणाऱ्या model ची accuracy सुद्धा जास्त दिसू शकते, पण असा model निरुपयोगी असतो. एक class दुसऱ्या class पेक्षा खूप मोठा असेल तेव्हा असं घडतं. म्हणून आधी class balance तपासा, म्हणजे एखादा साधा अंदाज किती score करेल हे तुम्हाला कळेल.
Ravindra Bagale's Tip – हिंदी
हर row के लिए 0 predict करने वाला model भी ऊँची accuracy दिखा सकता है, लेकिन ऐसा model बेकार होता है. ऐसा तब होता है जब एक class दूसरी class से बहुत बड़ी हो. इसलिए पहले class balance जाँचो, ताकि तुम्हें पता चले कि एक आसान अंदाज़ कितना score करेगा.