CoolFace
Apppublic

pranav-singh-developer-1/telecom-churn-predictor

sourceHugging Faceupdated 5mo agoView on Hugging Face
0likes
preprocessing.py38 linesDownload Raw Back to src
1import pandas as pd2from sklearn.base import BaseEstimator, TransformerMixin3 4class TelecomDataCleaner(BaseEstimator, TransformerMixin):5    def __init__(self):6        self.cols_to_drop = ['State', 'Area code', 'Phone number']7 8    def fit(self, X, y=None):9        return self10 11    def transform(self, X):12        X = X.copy()13        14        # --- FEATURE ENGINEERING ---15        # 1. Service Intensity: Total calls / Account Length16        # (High intensity often correlates with high engagement OR high friction)17        X['Service_Intensity'] = (X['Total day calls'] + X['Total eve calls']) / (X['Account length'] + 1)18        19        # 2. Cost Per Minute: Total Charge / Total Minutes20        # (Helps identify if a customer feels overcharged)21        X['Day_Cost_Per_Min'] = X['Total day charge'] / (X['Total day minutes'] + 1)22        23        # 3. Support Dependency: Customer Service Calls / Total Calls24        # (High ratio is a massive churn indicator)25        X['Support_Friction'] = X['Customer service calls'] / (X['Total day calls'] + 1)26 27        # Drop unnecessary columns28        X = X.drop(columns=self.cols_to_drop, errors='ignore')29        30        # Standardize column names for the model31        X.columns = [c.replace(' ', '_') for c in X.columns]32        return X33 34    def get_feature_names_out(self, input_features=None):35        # Update names to match the engineered features36        base_features = [f for f in input_features if f not in self.cols_to_drop]37        engineered = ['Service_Intensity', 'Day_Cost_Per_Min', 'Support_Friction']38        return [f.replace(' ', '_') for f in base_features] + engineered