练手项目:loan_prediction问题

这篇博客探讨了loan_prediction问题,通过数据探索发现信用历史对获得贷款的概率有显著影响。博主展示了不同变量的分布情况,如居住区域、信用历史,并进行了分类变量分析。接着,博主构建了预测模型,并报告了训练和测试得分,表明模型在预测贷款审批上有一定的准确性。
摘要由CSDN通过智能技术生成
# -*- coding: utf-8 -*-
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

%matplotlib inline

df = pd.read_csv('D:/my_project/Loan_Prediction/LoanPredictionProblem_train.csv')
df.head()
.dataframe thead tr:only-child th { text-align: right; } .dataframe thead th { text-align: left; } .dataframe tbody tr th { vertical-align: top; }
Loan_ID Gender Married Dependents Education Self_Employed ApplicantIncome CoapplicantIncome LoanAmount Loan_Amount_Term Credit_History Property_Area Loan_Status
0 LP001002 Male No 0 Graduate No 5849 0.0 NaN 360.0 1.0 Urban Y
1 LP001003 Male Yes 1 Graduate No 4583 1508.0 128.0 360.0 1.0 Rural N
2 LP001005 Male Yes 0 Graduate Yes 3000 0.0 66.0 360.0 1.0 Urban Y
3 LP001006 Male Yes 0 Not Graduate No 2583 2358.0 120.0 360.0 1.0 Urban Y
4 LP001008 Male No 0 Graduate No 6000 0.0 141.0 360.0 1.0 Urban Y
# 快速数据探索
df.describe() # get summary of numerical variables
.dataframe thead tr:only-child th { text-align: right; } .dataframe thead th { text-align: left; } .dataframe tbody tr th { vertical-align: top; }
ApplicantIncome CoapplicantIncome LoanAmount Loan_Amount_Term Credit_History
count 614.000000 614.000000 592.000000 600.00000 564.000000
mean 5403.459283 1621.245798 146.412162 342.00000 0.842199
std 6109.041673 2926.248369 85.587325 65.12041 0.364878
min 150.000000 0.000000 9.000000 12.00000 0.000000
25% 2877.500000 0.000000 100.000000 360.00000 1.000000
50% 3812.500000 1188.500000 128.000000 360.00000 1.000000
75% 5795.000000 2297.250000 168.000000 360.00000 1.000000
max 81000.000000 41667.000000 700.000000 480.00000 1.000000
# 对于非数值变量(e.g. Property_Area, Credit_History etc.), 观察频率分布是否合理。
df['Property_Area'].value_counts()
Semiurban 233 Urban 202 Rural 179 Name: Property_Area, dtype: int64 # 分布分析
# 研究变量的分布
<
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
在python中用函数优化以下代码while True: print('='*30) loan_type = input('请选择贷款类型:1.商业贷款 2.公积金贷款 3.组合贷款 0.算清楚了谢谢\n') if loan_type == '1' : loan_amount = float(input('请输入贷款金额(万)\n')) term = int(input('请输入贷款期限(年):\n')) if term <= 5 : mon_rate = (4.75 / 100) / 12 else: mon_rate = (4.90 / 100) / 12 mon_pay = loan_amount * 10000 * (mon_rate * ((1+mon_rate)**(term * 12))) / (((1 + mon_rate)** (term * 12)) - 1) all_pay = mon_pay * term * 12 interest = all_pay - loan_amount * 10000 print('每月月供参考(元):{:.2f}'.format(mon_pay)) print('支付利息(元):{:.2f}'.format(interest)) print('还款总额(元):{:.2f}'.format(all_pay)) elif loan_type == '2' : loan_amount = float(input('请输入贷款金额(万):\n')) term = int(input('请输入贷款期限(年):\n')) if term <= 5 : mon_rate = (2.75 / 100) / 12 else: mon_rate = (3.25 / 100) / 12 mon_pay = loan_amount * 10000 * (mon_rate * ((1 + mon_rate) ** (term * 12))) / (((1 + mon_rate)** (term * 12)) - 1) all_pay = mon_pay * term * 12 interest = all_pay - loan_amount * 10000 print('每月月供参考(元):{:.2f}'.format(mon_pay)) print('支付利息(元):{:.2f}'.format(interest)) print('还款总额(元):{:.2f}'.format(all_pay)) elif loan_type == '3': business_loan = float(input('请输入商业贷款金额(万):\n')) fund_loan = int(input('请输入公积金贷款金额(万):\n')) term = int(input('请输入贷款期限(年):\n')) if term <= 5: business_mon_rate = (4.75 / 100) / 12 fund_mon_rate = (2.75 / 100) / 12 else: business_loan = (4.90 / 100) / 12 fund_mon_rate = (3.25 / 100) / 12 business_mon_pay = business_loan * 10000 * (business_mon_rate * ((1 + business_mon_rate) ** (term * 12))) / (((1 + business_mon_rate)** (term * 12)) - 1) fund_mon_pay = fund_loan * 10000 * (fund_mon_rate * ((1 + fund_mon_rate) ** (term * 12))) / (((1 + fund_mon_rate) ** (term * 12)) - 1) mon_all_pay = business_mon_pay + fund_mon_pay all
03-09
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值