RuleVsML_Model
Use Case : Evaluate Customer Credit Worthiness based on the Amount Financed, Applicant Age and Total Debt
Use Case : Evaluate Customer Credit Worthiness based on the Amount Financed, Applicant Age and Total Debt
The logic is deterministic and static
The internal workflow is explainable and aligned with procedural and object oriented programming languages
The input-process-output structure is well-understood and has been used for over 50 years
Fine tunned to handle structured and semi-structed data
Sample Python code :
def rule_based_credit_score(income, age, debt):
""" Simple rule-based credit evaluation:
- Good: income > 50k, age > 25, debt < 20k
- Bad otherwise
"""
if income > 50000 and age > 25 and debt < 20000:
return "Good"
else:
return "Bad"
#Function Call
response = rule_based_credit_score(income=1000,age=21,debt=2100)
print(response )
Machine Learning (ML) logic is non-deterministic, probabilistic and depends on the model’s training process and historical data.
The internal ML workflow relies on matrix calculations, typically handled by ready-to-use libraries or packages. Most machine learning models function as black boxes, fine-tuned through hyperparameters
The train-test-validate-deploy workflow, where the model develops its internal heuristics, is comparatively abstract and lacks explain-ability
Fine tunned to manage structure, semi-structured and non-structured data such as images, text and speech
Sample Python code :
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
from sklearn.datasets import make_classification
import numpy as np
def ml_credit_score_model():
""" Trains a simple ML model on synthetic data. Features: income, age, debt . Labels: 1 (Good), 0 (Bad) """
X, y = make_classification(n_samples=1000, n_features=3, n_informative=3, n_redundant=0, n_clusters_per_class=1, random_state=42)
model = RandomForestClassifier()
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
model.fit(X_train, y_train)
return model
#Function Call
ml_model = ml_credit_score_model()
ml_model.predict([[40000,12,25000]])[0]
Compare Rule Based output with ML output
samples = [
(60000, 30, 10000), # Should be Good in both
(40000, 22, 25000), # Likely Bad in both
(55000, 23, 15000), # Might differ
]
def compare_methods(model, sample):
income, age, debt = sample
rule_result = rule_based_credit_score(income, age, debt)
ml_result = model.predict([[income, age, debt]])[0]
ml_result = "Good" if ml_result == 1 else "Bad"
print(f"\nInput: Income=${income}, Age={age}, Debt=${debt}")
print(f"Rule-Based Decision: {rule_result}")
print(f"ML-Based Decision: {ml_result}")
if rule_result != ml_result:
print("⚠️ Results differ due to flexibility/complexity of ML model.")
else:
print("✅ Both methods agree.")
# Function Call
for sample in samples:
compare_methods(ml_model, sample)
#OUTPUT
Input: Income=$60000, Age=30, Debt=$10000
Rule-Based Decision: Good
ML-Based Decision: Good
✅ Both methods agree.
Input: Income=$40000, Age=22, Debt=$25000
Rule-Based Decision: Bad
ML-Based Decision: Good
⚠️ Results differ due to flexibility/complexity of ML model.
Input: Income=$55000, Age=23, Debt=$15000
Rule-Based Decision: Bad
ML-Based Decision: Good
⚠️ Results differ due to flexibility/complexity of ML model.