✅
Data Science Project Series: Part 1 - Loan Prediction.Project goalPredict loan approval using applicant data.
Business value- Faster decisions
- Lower default risk
- Clear interview story
DatasetUse the common Loan Prediction dataset from analytics practice platforms.
TargetLoan_Status
Y approved
N rejected
Tech stack- Python
- Pandas
- NumPy
- Matplotlib
- Seaborn
- Scikit-learn
Step 1. Import librariesimport pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import LabelEncoder
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score, confusion_matrix, classification_report
Step 2. Load datadf = pd.read_csv("loan_prediction.csv")
df.head()
Step 3. Basic checksdf.shape
df.info()
df.isnull().sum()
Step 4. Data cleaningFill missing values
df['LoanAmount'].fillna(df['LoanAmount'].median(), inplace=True)
df['Loan_Amount_Term'].fillna(df['Loan_Amount_Term'].mode()[0], inplace=True)
df['Credit_History'].fillna(df['Credit_History'].mode()[0], inplace=True)
categorical_cols = ['Gender','Married','Dependents','Self_Employed']
for col in categorical_cols:
df[col].fillna(df[col].mode()[0], inplace=True)
Step 5. Exploratory Data AnalysisCredit history vs approval
sns.countplot(x='Credit_History', hue='Loan_Status', data=df)
plt.show()
Income distribution.python
sns.histplot(df['ApplicantIncome'], kde=True)
plt.show()
InsightApplicants with credit history have far higher approval rates.
Step 6. Feature engineeringCreate total income.
df['TotalIncome'] = df['ApplicantIncome'] + df['CoapplicantIncome']
# Log transform loan amount
df['LoanAmount_log'] = np.log(df['LoanAmount'])
Step 7. Encode categorical variablesle = LabelEncoder()
for col in df.select_dtypes(include='object').columns:
df[col] = le.fit_transform(df[col])
Step 8. Split features and targetX = df.drop('Loan_Status', axis=1)
y = df['Loan_Status']
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.3, random_state=42
)
Step 9. Build modelLogistic Regression.
model = LogisticRegression(max_iter=1000)
model.fit(X_train, y_train)
Step 10. Predictionsy_pred = model.predict(X_test)
Step 11. Evaluationaccuracy = accuracy_score(y_test, y_pred)
print("Accuracy:", accuracy)
confusion_matrix(y_test, y_pred)
Classification report.python
print(classification_report(y_test, y_pred))
Typical result
- Accuracy around 80 percent
- Strong precision for approved loans
- Recall needs focus for rejected loans
Step 12. Model improvement ideas- Use Random Forest
- Tune hyperparameters
- Handle class imbalance
- Track recall for rejected cases
Resume bullet example- Built loan approval prediction model using Logistic Regression
- Achieved ~80 percent accuracy
- Identified credit history as top approval driver
Interview explanation flow- Start with bank risk problem
- Explain feature impact
- Justify Logistic Regression
- Discuss recall vs accuracy
Double Tap ♥️ For More