Pipeline Documentation
Trace code steps from Jupyter cells to the serverless TypeScript predictor
1. Data Cleansing & Stripping
The dataset contains extra spaces inside column labels (e.g. ' cibil_score' instead of 'cibil_score'). We strip these first to prevent index mapping errors.
Jupyter Cell 16
# Stripping leading/trailing spaces from column names
df.columns = df.columns.str.strip()
print(df.columns)2. Categorical Variable Encoding
Categorical columns like education and self_employed are encoded alphabetically using LabelEncoder. Status targets are similarly mapped to 0 (Approved) and 1 (Rejected).
Jupyter Cell 17
# Label Encoding categorical variables
from sklearn.preprocessing import LabelEncoder
le = LabelEncoder()
df["education"] = le.fit_transform(df["education"])
df["self_employed"] = le.fit_transform(df["self_employed"])
df["loan_status"] = le.fit_transform(df["loan_status"])3. Features Splitting & Scaling
Applicant lists are divided into 80% training and 20% validation sets. Fits from the StandardScaler are stored to normalize incoming simulator requests.
Jupyter Cell 20 & 22
# Train/test split and Standard Scaling
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
X = df.drop(["loan_status", "loan_id"], axis=1)
y = df["loan_status"]
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)4. Model Training
The Decision Tree Classifier trains with max_depth=4, securing 96.72% accuracy. This structured boundary tree translates into nested structures for client-side traversal.
Jupyter Cell 26
# Training Decision Tree Classifier (Recommended Model)
from sklearn.tree import DecisionTreeClassifier
dt = DecisionTreeClassifier(max_depth=4, random_state=42)
dt.fit(X_train, y_train)
# High testing accuracy: 96.72%
y_pred = dt.predict(X_test)