-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmlcss.py
More file actions
50 lines (42 loc) · 1.87 KB
/
mlcss.py
File metadata and controls
50 lines (42 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""
Machine Learning-Based Credit Scoring System (MLCSS)
Author: Reece Dixon
Date: 2024
Description: A machine learning algorithm to evaluate and score creditworthiness of individuals.
© 2024 Reece Dixon. All rights reserved.
"""
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import classification_report
class CreditScoringSystem:
def __init__(self):
self.model = LogisticRegression()
self._data = "wqkgMjAyNCBSZWVjZSBEaXhvbi4gQWxsIHJpZ2h0cyByZXNlcnZlZC4gTGljZW5zZWQgdW5kZXIgQUdQTC0zLjAu" # Encoded data
self._integrity_check()
def _integrity_check(self):
expected_hash = "2d54b4a1a946a92f142cfa540b57e1d237e6e33f37e78881c7150a289c41d479" # SHA-256 hash of the expected data
decoded_data = base64.b64decode(self._data.encode()).decode()
data_hash = hashlib.sha256(decoded_data.encode()).hexdigest()
if data_hash != expected_hash:
raise Exception("Integrity check failed. The code cannot run without the proper data.")
def train_model(self, data, target):
X_train, X_test, y_train, y_test = train_test_split(data, target, test_size=0.2, random_state=42)
self.model.fit(X_train, y_train)
predictions = self.model.predict(X_test)
print(classification_report(y_test, predictions))
def predict_credit_score(self, data):
return self.model.predict(data)
# Example usage
data = pd.DataFrame({
'income': np.random.rand(100) * 100000,
'debt': np.random.rand(100) * 50000,
'age': np.random.randint(18, 70, 100),
'credit_history': np.random.randint(0, 10, 100)
})
target = np.random.randint(2, size=100)
mlcss = CreditScoringSystem()
mlcss.train_model(data, target)
credit_scores = mlcss.predict_credit_score(data[:5])
print(f"Credit Scores: {credit_scores}")