PavanKumarD commited on
Commit
bf275fd
ยท
verified ยท
1 Parent(s): 711ff76

Upload 4 files

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ src/dataset-2.csv filter=lfs diff=lfs merge=lfs -text
src/PaisaBazaar_ML_Submission.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
src/app.py ADDED
@@ -0,0 +1,398 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import joblib
4
+ from catboost import Pool
5
+ import plotly.graph_objects as go
6
+ import plotly.express as px
7
+ from datetime import datetime
8
+ import time
9
+
10
+ # Page configuration
11
+ st.set_page_config(
12
+ page_title="Credit Score Predictor",
13
+ page_icon="๐Ÿ’ณ",
14
+ layout="wide",
15
+ initial_sidebar_state="expanded"
16
+ )
17
+
18
+ # Custom CSS for better styling
19
+ st.markdown("""
20
+ <style>
21
+ .card{font-size: 3rem;
22
+
23
+ }
24
+ .main-header {
25
+ font-size: 3rem;
26
+ font-weight: bold;
27
+ text-align: center;
28
+ background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
29
+ -webkit-background-clip: text;
30
+ -webkit-text-fill-color: transparent;
31
+ margin-bottom: 1rem;
32
+ }
33
+
34
+ .sub-header {
35
+ text-align: center;
36
+ color: #666;
37
+ font-size: 1.2rem;
38
+ margin-bottom: 2rem;
39
+ }
40
+
41
+ .metric-card {
42
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
43
+ padding: 1rem;
44
+ border-radius: 10px;
45
+ color: white;
46
+ text-align: center;
47
+ margin: 0.5rem 0;
48
+ }
49
+
50
+ .stButton > button {
51
+ background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
52
+ color: white;
53
+ border: none;
54
+ border-radius: 20px;
55
+ padding: 0.5rem 2rem;
56
+ font-weight: bold;
57
+ width: 100%;
58
+ }
59
+
60
+ .prediction-good {
61
+ background: linear-gradient(135deg, #4CAF50, #45a049);
62
+ padding: 1rem;
63
+ border-radius: 10px;
64
+ color: white;
65
+ text-align: center;
66
+ font-size: 1.5rem;
67
+ font-weight: bold;
68
+ }
69
+
70
+ .prediction-standard {
71
+ background: linear-gradient(135deg, #FF9800, #F57C00);
72
+ padding: 1rem;
73
+ border-radius: 10px;
74
+ color: white;
75
+ text-align: center;
76
+ font-size: 1.5rem;
77
+ font-weight: bold;
78
+ }
79
+
80
+ .prediction-poor {
81
+ background: linear-gradient(135deg, #F44336, #D32F2F);
82
+ padding: 1rem;
83
+ border-radius: 10px;
84
+ color: white;
85
+ text-align: center;
86
+ font-size: 1.5rem;
87
+ font-weight: bold;
88
+ }
89
+ </style>
90
+ """, unsafe_allow_html=True)
91
+
92
+ # Load the model (with error handling)
93
+ @st.cache_resource
94
+ def load_model():
95
+ try:
96
+ return joblib.load("best_catboost_model.pkl")
97
+ except FileNotFoundError:
98
+ st.error("โš ๏ธ Model file not found. Please ensure 'best_catboost_model.pkl' is in the correct directory.")
99
+ return None
100
+
101
+ model = load_model()
102
+
103
+ # Categorical feature list
104
+ cat_features = ['Occupation', 'Credit_Mix', 'Payment_of_Min_Amount',
105
+ 'Payment_Behaviour', 'Type_of_Loan']
106
+
107
+ # Header
108
+ st.markdown('<h1 class="main-header">Credit Score Predictor</h1>', unsafe_allow_html=True)
109
+ st.markdown('<p class="sub-header">Get instant insights into your creditworthiness with our AI-powered predictor</p>', unsafe_allow_html=True)
110
+
111
+ # Sidebar for quick info
112
+ with st.sidebar:
113
+ st.markdown("### ๐Ÿ“Š About Credit Scores")
114
+ st.info("""
115
+ **Good Credit (750+)**
116
+ โœ… Best loan rates \n
117
+ โœ… Easy approvals \n
118
+ โœ… Premium credit cards \n
119
+
120
+ **Standard Credit (650-749)**
121
+ โš ๏ธ Moderate rates \n
122
+ โš ๏ธ Standard approvals \n
123
+
124
+ **Poor Credit (<650)**
125
+ โŒ High interest rates \n
126
+ โŒ Limited options \n
127
+ """)
128
+
129
+ st.markdown("### ๐ŸŽฏ Tips for Better Credit")
130
+ st.success("""
131
+ โ€ข Pay bills on time \n
132
+ โ€ข Keep credit utilization low \n
133
+ โ€ข Maintain old accounts \n
134
+ โ€ข Monitor credit report \n
135
+ โ€ข Diversify credit types \n
136
+ """)
137
+
138
+ # Main content in tabs
139
+ tab1, tab2, tab3= st.tabs(["๐Ÿ” Predict Credit Score", "๐Ÿ“ˆ Factors Affecting Credit Score", "๐Ÿ’ก Recommendations"])
140
+
141
+ with tab1:
142
+ if model is None:
143
+ st.stop()
144
+
145
+ # Personal Information Section
146
+ st.markdown("### ๐Ÿ‘ค Personal Information")
147
+ col1, col2, col3 = st.columns(3)
148
+
149
+ with col1:
150
+ name = st.text_input("๐Ÿ“ Full Name", placeholder="Enter your full name")
151
+ age = st.slider("๐ŸŽ‚ Age", min_value=18, max_value=100, value=30)
152
+
153
+ with col2:
154
+ month = st.selectbox("๐Ÿ“… Month", range(1, 13), index=0)
155
+ occupation = st.selectbox("๐Ÿ’ผ Occupation", [
156
+ "Scientist", "Teacher", "Engineer", "Manager", "Doctor",
157
+ "Lawyer", "Architect", "Developer", "Accountant", "Other"
158
+ ])
159
+
160
+ with col3:
161
+ annual_income = st.number_input("๐Ÿ’ฐ Annual Income ($)", min_value=0.0, value=50000.0, step=1000.0)
162
+ monthly_inhand_salary = st.number_input("๐Ÿ’ต Monthly Salary ($)", min_value=0.0, value=4000.0, step=100.0)
163
+
164
+ st.divider()
165
+
166
+ # Banking Information Section
167
+ st.markdown("### ๐Ÿฆ Banking & Credit Information")
168
+ col4, col5, col6 = st.columns(3)
169
+
170
+ with col4:
171
+ num_bank_accounts = st.slider("๐Ÿฆ Bank Accounts", min_value=0, max_value=20, value=3)
172
+ num_credit_card = st.slider("๐Ÿ’ณ Credit Cards", min_value=0, max_value=20, value=2)
173
+ interest_rate = st.slider("๐Ÿ“ˆ Interest Rate (%)", min_value=0.0, max_value=50.0, value=12.0, step=0.1)
174
+
175
+ with col5:
176
+ num_of_loan = st.slider("๐Ÿ  Number of Loans", min_value=0, max_value=20, value=2)
177
+ type_of_loan = st.multiselect("๐Ÿท๏ธ Loan Types", [
178
+ "Auto Loan", "Personal Loan", "Home Loan", "Student Loan",
179
+ "Credit Card Loan", "Business Loan"
180
+ ], default=["Auto Loan", "Personal Loan"])
181
+
182
+ # Convert multiselect to string
183
+ type_of_loan_str = ", ".join(type_of_loan) if type_of_loan else "No Loan"
184
+
185
+ with col6:
186
+ credit_mix = st.selectbox("๐ŸŽฏ Credit Mix", ["Good", "Standard", "Poor"], index=0)
187
+ payment_of_min_amount = st.selectbox("๐Ÿ’ธ Pay Minimum Amount", ["Yes", "No"], index=0)
188
+ payment_behaviour = st.selectbox("๐Ÿ“Š Payment Behaviour", [
189
+ "High_spent_Small_value_payments",
190
+ "Low_spent_Large_value_payments",
191
+ "High_spent_Medium_value_payments",
192
+ "Low_spent_Medium_value_payments",
193
+ "High_spent_Large_value_payments",
194
+ "Low_spent_Small_value_payments"
195
+ ])
196
+
197
+ st.divider()
198
+
199
+ # Financial Details Section
200
+ st.markdown("### ๐Ÿ’น Financial Details")
201
+ col7, col8, col9 = st.columns(3)
202
+
203
+ with col7:
204
+ delay_from_due_date = st.slider("โฐ Days Late on Payments", min_value=0, max_value=60, value=5)
205
+ num_of_delayed_payment = st.slider("โš ๏ธ Delayed Payments Count", min_value=0, max_value=50, value=3)
206
+ changed_credit_limit = st.number_input("๐Ÿ“Š Credit Limit Changes", value=500.0, step=100.0)
207
+
208
+ with col8:
209
+ num_credit_inquiries = st.slider("๐Ÿ” Credit Inquiries", min_value=0, max_value=20, value=2)
210
+ outstanding_debt = st.number_input("๐Ÿ’ณ Outstanding Debt ($)", min_value=0.0, value=1500.0, step=100.0)
211
+ credit_utilization_ratio = st.slider("๐Ÿ“ˆ Credit Utilization (%)", min_value=0.0, max_value=100.0, value=25.0, step=0.1)
212
+
213
+ with col9:
214
+ credit_history_age = st.slider("๐Ÿ“… Credit History (months)", min_value=0, max_value=600, value=200)
215
+ total_emi_per_month = st.number_input("๐Ÿ’ฐ Monthly EMI ($)", min_value=0.0, value=200.0, step=50.0)
216
+ amount_invested_monthly = st.number_input("๐Ÿ“ˆ Monthly Investment ($)", min_value=0.0, value=100.0, step=25.0)
217
+ monthly_balance = st.number_input("๐Ÿ’ต Monthly Balance ($)", value=800.0, step=100.0)
218
+
219
+ st.divider()
220
+
221
+ # Prediction Section
222
+ col_pred1, col_pred2, col_pred3 = st.columns([1, 2, 1])
223
+
224
+ with col_pred2:
225
+ if st.button("๐Ÿ”ฎ Predict My Credit Score", type="primary"):
226
+ if not name:
227
+ st.warning("โš ๏ธ Please enter your name to continue.")
228
+ else:
229
+ # Show loading animation
230
+ with st.spinner('๐Ÿ”„ Analyzing your credit profile...'):
231
+ time.sleep(2) # Simulate processing time
232
+
233
+ # Prepare input DataFrame
234
+ data = pd.DataFrame([{
235
+ 'Month': month,
236
+ 'Age': age,
237
+ 'Occupation': occupation,
238
+ 'Annual_Income': annual_income,
239
+ 'Monthly_Inhand_Salary': monthly_inhand_salary,
240
+ 'Num_Bank_Accounts': num_bank_accounts,
241
+ 'Num_Credit_Card': num_credit_card,
242
+ 'Interest_Rate': interest_rate,
243
+ 'Num_of_Loan': num_of_loan,
244
+ 'Type_of_Loan': type_of_loan_str,
245
+ 'Delay_from_due_date': delay_from_due_date,
246
+ 'Num_of_Delayed_Payment': num_of_delayed_payment,
247
+ 'Changed_Credit_Limit': changed_credit_limit,
248
+ 'Num_Credit_Inquiries': num_credit_inquiries,
249
+ 'Credit_Mix': credit_mix,
250
+ 'Outstanding_Debt': outstanding_debt,
251
+ 'Credit_Utilization_Ratio': credit_utilization_ratio,
252
+ 'Credit_History_Age': credit_history_age,
253
+ 'Payment_of_Min_Amount': payment_of_min_amount,
254
+ 'Total_EMI_per_month': total_emi_per_month,
255
+ 'Amount_invested_monthly': amount_invested_monthly,
256
+ 'Payment_Behaviour': payment_behaviour,
257
+ 'Monthly_Balance': monthly_balance
258
+ }])
259
+
260
+ # Make prediction
261
+ try:
262
+ pool = Pool(data, cat_features=cat_features)
263
+ prediction = model.predict(pool)
264
+ result = prediction[0]
265
+
266
+ # Display result with appropriate styling
267
+ if result == "Good":
268
+ st.markdown(f'<div class="prediction-good">๐ŸŽ‰ Congratulations {name}!<br>Your Credit Score is: <strong>{result}</strong></div>', unsafe_allow_html=True)
269
+ st.balloons()
270
+ elif result == "Standard":
271
+ st.markdown(f'<div class="prediction-standard">๐Ÿ‘ Hi {name}!<br>Your Credit Score is: <strong>{result}</strong></div>', unsafe_allow_html=True)
272
+ st.snow()
273
+ else:
274
+ st.markdown(f'<div class="prediction-poor">โšก Hi {name}!<br>Your Credit Score is: <strong>{result}</strong><br>There\'s room for improvement!</div>', unsafe_allow_html=True)
275
+
276
+ # Store result in session state for other tabs
277
+ st.session_state.prediction = result
278
+ st.session_state.user_data = data
279
+
280
+ except Exception as e:
281
+ st.error(f"โŒ An error occurred during prediction: {str(e)}")
282
+
283
+ with tab2:
284
+ # Credit factors impact
285
+ # st.markdown("### ๐ŸŽฏ Factors Affecting Credit Score")
286
+
287
+ factors = {
288
+ 'Type_of_Loan': 9.6518,
289
+ 'Occupation':8.4725,
290
+ 'Month ':6.2643,
291
+ 'Outstanding_Debt':5.8894,
292
+ 'Credit_Mix': 5.3340,
293
+ 'Changed_Credit_Limit':4.9477 ,
294
+ 'Delay_from_due_date':4.8124,
295
+ 'Credit_History_Age' :4.6812,
296
+ 'Age':4.6376,
297
+ 'Interest_Rate':4.5192
298
+ }
299
+
300
+ fig_bar = go.Figure([go.Bar(
301
+ x=list(factors.keys()),
302
+ y=list(factors.values()),
303
+ marker_color=[
304
+ '#3a1c71', # darkest
305
+ '#4a00e0',
306
+ '#6a11cb',
307
+ '#8e2de2',
308
+ '#764ba2',
309
+ '#764ba2',
310
+ '#2575fc',
311
+ '#667eea',
312
+ '#667eea',
313
+ '#667eea' # lightest
314
+ ]
315
+ )])
316
+
317
+ fig_bar.update_layout(
318
+ title="Credit Score Impact Factors",
319
+ xaxis_title="Factors",
320
+ yaxis_title="Impact Score",
321
+ height=400
322
+ )
323
+
324
+ st.plotly_chart(fig_bar, use_container_width=True)
325
+
326
+ with tab3:
327
+ st.markdown("### ๐Ÿ’ก Personalized Recommendations")
328
+
329
+ if 'prediction' in st.session_state:
330
+ result = st.session_state.prediction
331
+
332
+ if result == "Good":
333
+ st.success("๐ŸŽ‰ **Excellent Credit Score!** Keep up the great work!")
334
+ st.markdown("""
335
+ **To maintain your excellent score:**
336
+ - Continue paying all bills on time
337
+ - Keep credit utilization below 30%
338
+ - Don't close old credit accounts
339
+ - Monitor your credit report regularly
340
+ - Consider becoming an authorized user on family accounts
341
+ """)
342
+
343
+ elif result == "Standard":
344
+ st.warning("๐Ÿ‘ **Good Credit Score!** Here's how to improve:")
345
+ st.markdown("""
346
+ **Steps to reach 'Good' status:**
347
+ - Set up automatic payments to avoid late fees
348
+ - Pay down existing debt to improve utilization ratio
349
+ - Don't apply for new credit cards frequently
350
+ - Keep old accounts open to maintain credit history
351
+ - Consider a secured credit card if needed
352
+ """)
353
+
354
+ else:
355
+ st.error("โšก **Credit Score Needs Improvement!** Don't worry, here's your action plan:")
356
+ st.markdown("""
357
+ **Priority actions to improve your score:**
358
+ 1. **Pay all bills on time** - This is the most important factor
359
+ 2. **Reduce credit card balances** - Aim for under 30% utilization
360
+ 3. **Don't close old accounts** - They help your credit history length
361
+ 4. **Check your credit report** - Look for errors and dispute them
362
+ 5. **Consider a secured credit card** - To build positive payment history
363
+ 6. **Pay more than the minimum** - Reduces debt faster
364
+ """)
365
+ else:
366
+ st.info("๐Ÿ” **Get your credit score prediction first to see personalized recommendations!**")
367
+
368
+ st.markdown("""
369
+ ### General Credit Improvement Tips:
370
+
371
+ **๐ŸŽฏ Quick Wins:**
372
+ - Set up automatic bill payments
373
+ - Pay credit cards twice per month
374
+ - Request credit limit increases
375
+ - Become an authorized user on family accounts
376
+
377
+ **๐Ÿ“ˆ Long-term Strategies:**
378
+ - Diversify your credit mix (cards, loans, mortgage)
379
+ - Keep old accounts open
380
+ - Monitor credit reports monthly
381
+ - Avoid hard inquiries when possible
382
+
383
+ **๐Ÿšจ Red Flags to Avoid:**
384
+ - Missing payments (even by a day)
385
+ - Maxing out credit cards
386
+ - Closing old accounts
387
+ - Co-signing loans carelessly
388
+ """)
389
+
390
+ # Footer
391
+ st.divider()
392
+ st.markdown("""
393
+ <div style='text-align: center; color: #666; padding: 1rem;'>
394
+ <p>๐Ÿ’ณ <strong>Credit Score Predictor</strong> | Built with โค๏ธ using Streamlit & CatBoost</p>
395
+ <p><small>โš ๏ธ This is a predictive tool and should not be considered as financial advice.
396
+ Consult with financial professionals for important credit decisions.</small></p>
397
+ </div>
398
+ """, unsafe_allow_html=True)
src/best_catboost_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c9358eeb59c63d26b42bdb2314f4987cc628ad4f182a9150208a2889edc40b55
3
+ size 38244400
src/dataset-2.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d56d2ee3dc5194da72fbe0a25a86832cad62ed5601b77b761c0bdac372f5920f
3
+ size 30752741