MCPcopy Create free account
hub / github.com/GitsSaikat/PyGen / DataPreprocessor

Class DataPreprocessor

data/AutoML/reference_code.py:27–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25 self.deployer = ModelDeployer()
26
27class DataPreprocessor:
28
29
30 def __init__(self):
31 self.numerical_imputer = SimpleImputer(strategy='mean')
32 self.categorical_imputer = SimpleImputer(strategy='most_frequent')
33 self.scaler = StandardScaler()
34 self.label_encoders = {}
35
36 def preprocess(self, data: pd.DataFrame) -> pd.DataFrame:
37
38 processed_data = data.copy()
39
40 # Identify numerical and categorical columns
41 numerical_cols = processed_data.select_dtypes(include=['int64', 'float64']).columns
42 categorical_cols = processed_data.select_dtypes(include=['object']).columns
43
44 # Handle missing values
45 if len(numerical_cols) > 0:
46 processed_data[numerical_cols] = self.numerical_imputer.fit_transform(processed_data[numerical_cols])
47 if len(categorical_cols) > 0:
48 processed_data[categorical_cols] = self.categorical_imputer.fit_transform(processed_data[categorical_cols])
49
50 # Encode categorical variables
51 for col in categorical_cols:
52 self.label_encoders[col] = LabelEncoder()
53 processed_data[col] = self.label_encoders[col].fit_transform(processed_data[col])
54
55 # Scale numerical features
56 if len(numerical_cols) > 0:
57 processed_data[numerical_cols] = self.scaler.fit_transform(processed_data[numerical_cols])
58
59 return processed_data
60
61class FeatureEngineer:
62

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected