欢迎关注天善智能,我们是专注于商业智能BI,人工智能AI,大数据分析与挖掘领域的垂直社区,学习,问答、求职一站式搞定!
对商业智能BI、大数据分析挖掘、机器学习,python,R等数据领域感兴趣的同学加微信:tstoutiao,邀请你进入数据爱好者交流群,数据爱好者们都在这儿。
作者:废才大叔
个人公众号: 废才数据挖掘
为了让更多小伙伴了解申请评分卡建模过程,小编利用某工业数据,做了一个简略版基于Python数据分析。该评分卡制作比较粗略,有部分步骤并不是严格按照工业级别评分卡流程来制作,本文仅仅为大家做一个评分卡流程梳理。
定义Y是需要根据业务要求,查看账龄表与滚动率定义,这里仅仅是作为一个分享,小编把逾期天数大于等于30天设定为1 ,为避免模型干扰以及更准确预测去除0-30客户,0天定义为0
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import matplotlib
from sklearn.model_selection import GridSearchCV
import lightgbm as lgb
from sklearn.cross_validation import train_test_split,cross_val_score
from sklearn.metrics import confusion_matrix
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import precision_score, recall_score, f1_score, roc_auc_score,accuracy_score
from sklearn.model_selection import StratifiedKFold,KFold,StratifiedShuffleSplit
from sklearn.tree import _tree
from sklearn import tree
import warningsmatplotlib.use('qt4agg')#指定默认字体
matplotlib.rcParams['font.sans-serif'] = ['SimHei']
matplotlib.rcParams['font.family']='sans-serif'#解决负号'-'显示为方块的问题
matplotlib.rcParams['axes.unicode_minus'] = False
pd.set_option('display.max_rows', 100)
pd.set_option('display.max_columns', 10000)
%matplotlib inline
warnings.filterwarnings("ignore")
def readfile(is_df): if is_df: df=pd.read_csv("D:/mydata/md5data.csv") return df
df=readfile(is_df=True)# 读取数据集
df.info()
def value_count(df): name=df.columns lenth=[] names=[] for i in name: lenth.append(len(df[i].value_counts())) names.append(i) lenth=pd.DataFrame(lenth) names=pd.DataFrame(names) valuecounts=pd.concat([names,lenth],axis=1) valuecounts.columns=["name","vary_num"] return valuecounts
value_count(df)##查看每一种变量分类
def plotbar(df,var,target): a=df.groupby([var])[target].mean().reset_index() b=df.groupby([var])[ta