问题定义

这是一个贷款的审批问题,假设你是一个银行的贷款审批员,现在有客户需要一定额度的贷款,他们填写了个人的信息(信息在datas.txt中给出),你需要根据他们的信息,建立一个分类模型,判断是否可以给他们贷款。

请根据所给的信息,建立分类模型,评价模型,同时将模型建立过程简单介绍一下,同时对各特征进行简单的解释说明。

Dataset

用户id,年龄,性别,申请金额,职业类型,教育程度,婚姻状态,房屋类型,户口类型,贷款用途,公司类型,薪水,贷款标记:0不放贷,1同意放贷

Data preprocessing

在对数据进行建模时,用户ID是没有用的。在描述用户信息的几个维度数据中,年龄,申请金额,薪水是连续值,剩下的是离散值。

通过观察发现有些数据存在数据缺失的情况,需要对这些数据进行处理,比如直接删除或者通过缺失值补全。

The Logit Function

The Logistic Regression

Model Data

 #逻辑回归模型
#对银行客户是否放贷进行分类 import pandas
import numpy
import matplotlib.pyplot as plt
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import roc_curve, roc_auc_score data = pandas.read_csv("datas.csv")
data = data.dropna() # Randomly shuffle our data for the training and test set
admissions = data.loc[numpy.random.permutation(data.index)] # train with 700 and test with the following 300, split dataset
num_train = 14968
data_train = admissions[:num_train]
data_test = admissions[num_train:] # Fit Logistic regression to admit with features using the training set
logistic_model = LogisticRegression()
logistic_model.fit(data_train[['Age','Gender','AppAmount','Occupation',
'Education','Marital','Property','Residence',
'LoanUse','Company','Salary']], data_train['Label']) # Print the Models Coefficients
print(logistic_model.coef_) # .predict() using a threshold of 0.50 by default
predicted = logistic_model.predict(data_train[['Age','Gender','AppAmount','Occupation',
'Education','Marital','Property','Residence',
'LoanUse','Company','Salary']]) # The average of the binary array will give us the accuracy
accuracy_train = (predicted == data_train['Label']).mean() # Print the accuracy
print("Accuracy in Training Set = {s}".format(s=accuracy_train)) # Predicted to be admitted
predicted = logistic_model.predict(data_test[['Age','Gender','AppAmount','Occupation',
'Education','Marital','Property','Residence',
'LoanUse','Company','Salary']]) # What proportion of our predictions were true
accuracy_test = (predicted == data_test['Label']).mean()
print("Accuracy in Test Set = {s}".format(s=accuracy_test)) # Predict the chance of label from those in the training set
train_probs = logistic_model.predict_proba(data_train[['Age','Gender','AppAmount','Occupation',
'Education','Marital','Property','Residence',
'LoanUse','Company','Salary']])[:,1] test_probs = logistic_model.predict_proba(data_test[['Age','Gender','AppAmount','Occupation',
'Education','Marital','Property','Residence',
'LoanUse','Company','Salary']])[:,1] # Compute auc for training set
auc_train = roc_auc_score(data_train["Label"], train_probs) # Compute auc for test set
auc_test = roc_auc_score(data_test["Label"], test_probs) # Difference in auc values
auc_diff = auc_train - auc_test # Compute ROC Curves
roc_train = roc_curve(data_train["Label"], train_probs)
roc_test = roc_curve(data_test["Label"], test_probs) # Plot false positives by true positives
plt.plot(roc_train[0], roc_train[1])
plt.plot(roc_test[0], roc_test[1])

Logistic Regression:银行贷款申请审批实例的更多相关文章

  1. Logistic Regression vs Decision Trees vs SVM: Part II

    This is the 2nd part of the series. Read the first part here: Logistic Regression Vs Decision Trees ...

  2. 统计学习方法笔记 Logistic regression

    logistic distribution 设X是连续随机变量,X服从逻辑斯谛分布是指X具有下列分布函数和密度函数: 式中,μ为位置参数,γ>0为形状参数. 密度函数是脉冲函数 分布函数是一条S ...

  3. Machine Learning - 第3周(Logistic Regression、Regularization)

    Logistic regression is a method for classifying data into discrete outcomes. For example, we might u ...

  4. 【机器学习】Octave 实现逻辑回归 Logistic Regression

    ex2data1.txt ex2data2.txt 本次算法的背景是,假如你是一个大学的管理者,你需要根据学生之前的成绩(两门科目)来预测该学生是否能进入该大学. 根据题意,我们不难分辨出这是一种二分 ...

  5. 机器学习之LinearRegression与Logistic Regression逻辑斯蒂回归(三)

    一 评价尺度 sklearn包含四种评价尺度 1 均方差(mean-squared-error) 2 平均绝对值误差(mean_absolute_error) 3 可释方差得分(explained_v ...

  6. Python机器学习算法 — 逻辑回归(Logistic Regression)

    逻辑回归--简介 逻辑回归(Logistic Regression)就是这样的一个过程:面对一个回归或者分类问题,建立代价函数,然后通过优化方法迭代求解出最优的模型参数,然后测试验证我们这个求解的模型 ...

  7. 通俗地说逻辑回归【Logistic regression】算法(二)sklearn逻辑回归实战

    前情提要: 通俗地说逻辑回归[Logistic regression]算法(一) 逻辑回归模型原理介绍 上一篇主要介绍了逻辑回归中,相对理论化的知识,这次主要是对上篇做一点点补充,以及介绍sklear ...

  8. 机器学习-非线性回归(Logistic Regression)及应用

    1. 概率 1.1 定义:概率(Probability):对一件事情发生的可能性的衡量. 1.2 范围:0 <= P <= 1 1.3 计算方法: 1.3.1 根据个人置信 1.3.2 根 ...

  9. 机器学习——逻辑回归(Logistic Regression)

    1 前言 虽然该机器学习算法名字里面有"回归",但是它其实是个分类算法.取名逻辑回归主要是因为是从线性回归转变而来的. logistic回归,又叫对数几率回归. 2 回归模型 2. ...

随机推荐

  1. react重学

    知识点一:react解析中 return {__html:rawMarkup}; 这里的html前边用的是双下划线(谢谢学妹的指点)

  2. Linux 操作命令列表记录

    Linux 操作命令列表记录 SSH登录 登录 ## 范式 ssh [username]@[host] ## 例 ssh -p 1222 root@10.0.0.1 使用非默认端口(ssh默认端口22 ...

  3. TortoiseSVN 1.8 关于右键的设置

    以前用SVN但都是 IDE 自己集成的插件,最近使用 android studio 发现居然自己不带SVN command line插件,非得自己单独装一个,于是使用了 TortoiseSVN ,但用 ...

  4. JQuery-常用小组件

    常用的小组件记录 1. 单选框.复选框重置样式效果 参考: http://www.cnblogs.com/sanshi/p/4369375.html 三生石上 参考: http://www.jq22. ...

  5. bootstrap的总结1 - 网格系统

    1.Bootstrap 网格系统 1)下表总结了 Bootstrap 网格系统如何跨多个设备工作: 2)Bootstrap 网格的基本结构 <div class="container& ...

  6. [DP优化方法之虚树]

    首先我们看一篇文章 转自xyz: 给出一棵树. 每次询问选择一些点,求一些东西.这些东西的特点是,许多未选择的点可以通过某种方式剔除而不影响最终结果. 于是就有了建虚树这个技巧..... 我们可以用l ...

  7. sap 设备cnsapwin不支持页格式*****

    SAP SMARTFORMS 打印 CNSAPWIN 不支持页格式 解决办法: 在smartforms里的表格属性虽然定义了要打印的页格式 ZUNIA5 ,但是打印时会提示错误:" CNSA ...

  8. 基于PHP——简单的WSDL的创建(WSDL篇)

    1.建立WSDL文件      建立WSDL的工具很多,eclipse.zendstudio.vs都可以,我个人建议自己写,熟悉结构,另外自动工具对xml schame类型支持在类型中可能会报错. 下 ...

  9. ARXObject的入门学习

    刚刚学习一样新东西的时候,首先要解决的几个问题 1. 任何搭建一个项目环境: 2. 新建一个项目的流程: 3. 调试: 4. 熟悉其API: 5. 错误积累与解决办法: 6. 其中隐含的语法知识和UM ...

  10. lvs 会话保持(转发)

    lvs & keepalived的tcp 长连接的问题解决办法 虽然应用keepalived搞定了后端服务负载均衡和高可用性问题,但是在具体应用的时候,还是要注意很多问题.很多应用都用tcp或 ...