关键词不能为空

当前您在: 主页 > 英语 >

使用决策树的预测建模

作者:高考题库网
来源:https://www.bjmy2z.cn/gaokao
2021-02-10 16:47
tags:

-

2021年2月10日发(作者:tension)


Chapter 2


使用决策树的预测建模




2.1



2.2



2.3
























问题和数据探索


.................... .................................................. ............................................


建模问题和数据难点


.................. .................................................. .......................................


生成和解释决策树



.


.............................................. .................................



误!未定义书签。



2.1



问题和数据探索



内容:



问题和数据



初步数据探索




问题和数据



a.


预测建模问题



一家金融服务公司为其 客户提供房屋净值信贷额度。


该公司曾把该项贷款扩展给了数千


客户,其中的许多接收者(大约


20%


)有贷款欺诈行为。该公 司希望使用地理信息、人


口信息、和经济状况信息变量建立一个模型预测一个申请人将来 会不会欺诈。



b.


输入数据源



在对数据进行了分析之 后,


该公司选择了


12


个预测变量来建 立每一个申请人是否欺诈的


模型。输出变量(或目标)变量


(B AD)


表示申请人在房屋净值信贷中是否有欺诈活动。


这些变量 及其模型角色、测量水平、变量描述列表如下。




2.1



数据集合的变量





Name


Model


Role


Target


Measurement


Level


Binary


Description


BAD


1=defaulted on loan, 0=paid


back loan


HomeImp=home


improvement, DebtCon=debt


consolidation


Six occupational categories


Amount of loan request


Amount due on existing


mortgage


Value of current property


Debt-to-income ratio


Years at present job


Number of major derogatory


reports


Number of trade lines


Number of delinquent trade


lines


Age of oldest trade line in


months


Number of recent credit


inquiries


REASON


Input


Binary


JOB


LOAN


MORTDUE


Input


Input


Input


Nominal


Interval


Interval


V


ALUE


DEBTINC


YOJ


DEROG


Input


Input


Input


Input


Interval


Interval


Interval


Interval


CLNO


DELINQ


Input


Input


Interval


Interval


CLAGE


Input


Interval


NINQ


Input


Interval



需要的结果-信用评分模型



该信用评 分模型给每一个贷款申请人计算还贷欺诈的概率。在此要设定一个阈值,


欺诈

< p>
概率超过阈值的那些申请人将建议不批准。







建立项目和数据初步探索



建造简单的 过程流(


Flow




1.



假定


My Project


项目的< /p>


Project1


框图是开着的,通过从工具条上(或

< p>
Tools


标签)


拖动


I nput Data Source


节点到


diagram


工作区把节点加到


Project1


框图中 。



2.




Multiplot


节点工作区


Input Data Source


节点的右边


.


你的框图看起来如下图



连接工作区的两个节点


:


开始时












最后






调用输入数据



这个例子使用



SAMPSIO


文件夹的



HMEQ


数据集合


.




1.



要指定数据集合,


双击


Input Data Source



节点,


或右击该节点并选择



Open…


. Data


标签处于激活状态


.


你的窗口如下


:




2.



点击



Select…



来选择数据集合


.


或者把数据集合的名称键入进来。



3.



SASUSER


文件夹是缺省文件夹


.


要浏览



SAMPSIO



文件夹的数据集合


,


点击



从这些文件夹里选择


SAMPSIO






4.




SAMPSIO



文件夹的数据集合里选择


HMEQ



然后选


OK


.


下面的对话框打开:




5.



可以看到该数据集合里有



5,960


个观测


(行)




13


个变量



(



).


SAMPSIO


.HMEQ



源数据


.


注意在右下角指示的是


metadata


(元数据)

< p>


样本大小为


2,000.


所有分析包必须决定在分析中如何使用变量


. EM

< p>
使用元数据对如何使用每一个变量作


一个初步的评估。按缺省方式,它从感 兴趣的数据集合里随机抽取


2,000


个观测记录,


并使用这里的信息为每一个变量确定其模型中的作用和变量类型。


要抽取 一个较大的样


本,你得选择对话框右下角


Change…



按钮


.


1.



点击



Variables



标签可看到所有的变量及其相关的指定


.



2.



点击第一列的标头,


Name,


这些 变量就按名称的顺序排列。把窗口拉大你会看到所


有的变量。下表显示了


13


个变量的部分信息


.



注意有两列显灰色。


这些列代表这个节点里不能改变的


SAS


数据集合的信息。


Type



者是字符型


(


cha r


)


或者是数值型


(

< br>num


)


,它对一个变量如何被使用有影响。


2,000


元数


据样本的


Type


的值和不重复数值个数用于确定模型以及测量水平


.


第一个变量



BAD

< br>是目标变量


.


尽管


BAD


是数据集合里的一个数值变量,


EM


把它认 作


binary



二元变量)因为在元 数据样本里它只有两个不同的非缺失值。所有二元变量


的模型角色的缺省设置都是输入变 量(


input


)。



在做分析之前你需要把


BAD


的模


型角色改为目标变量。




The next five variables (CLAGE through DEROG) have the measurement level


interval



because they are numeric variables in the SAS data set and have more than 10 distinct levels


in the metadata sample. The model role for all


interval


variables is set to


input


by


default.



The variables JOB and REASON are both character variables in the data set, but they have


different measurement levels. REASON is binary because it has only two distinct nonmissing


levels in the metadata sample. The model role for JOB, however, is nominal because it is a


character variable with more than two levels.


For the purpose of this analysis, treat the remaining variables as interval variables.



?



At times, variables such as DEROG and DELINQ will be assigned the model role of


ordinal


. A variable is listed as ordinal when it is a numeric variable with more than


two but no more than ten distinct nonmissing levels in the metadata sample. This


often occurs with counting variables, such as a variable for the number of children.


Because this assignment depends on the metadata sample, the measurement level of


DEROG or DELINQ for your analysis might be set to


ordinal


. All ordinal


variables are set to have the


input


model role; however, you treat these variables as


interval inputs for the purpose of this analysis.


确定目标变量



BAD


是这个分析的反应变量,因此要把


BAD


的模型作用 改为


target


.



要改变模型作用信息,方法如下:



1.



把光标头指向


BAD


行的


Model Role


一栏并右击。




2.



从弹出菜单选择



Set Model Role



?



target


.


检查分布



你可以检查元数据样本里每 一个变量的数值分布。要查看


BAD


的分布

:


1.



把光标头指向


BAD


变量


Name



.



2.



右击鼠标,你可以按名称给变量 排序、找变量、或者查看


BAD


的分布


.



3.



选择



View Distribution of BAD



查看


BAD


的分布




To obtain additional information, select the the View Info tool,


, from the toolbar at the


top of the window and click on one of the bars. Enterprise Miner displays the level and the


proportion of observations represented by the bar. These plots provide an initial overview of


the data. For this example, approximately 20% of the observations were loans where the


client defaulted. Because the plots are based on the metadata sample, they may vary slightly


due to the differences in the sampled observations, but the bar for BAD=1 should represent


approximately 20% of the data. Close the Variable Histogram window when you are finished


inspecting the plot. You can evaluate the distribution of other variables as desired.


修改变量信息



保证余下变量的模型作用和测量水平信息是正确的。如果必要,可以把

< br>DEROG


的测量


水平改为



interval


.


要修改测量水平信息


:


1.



把光标头指向

< br>DEROG


行的测量(


Measurement


)栏,并右击鼠标




2.



从弹出菜单选择


Set Measurement



?



interval





查看描述统计量



元数据可用来计算描述统计量。选择


Interval Variables


标签




你可以查看连续变量的最小值、


最大值、


均值、


标准差、


缺失记录的百分数、


偏度和< /p>




度。根据数据的商务知识,查看最小 值和最大值指的是有没有异常值。注意


DEBTINC


变量的缺 失值百分数很高


(21%).


选择类别变量


Class Variables



标签




查看数据的水平级数、缺失值百分数、以及变量的排序方式。 注意


BAD


变量是降序,


而其它变量是 升序。


这是因为它是二元目标变量。


通常对于二元变量当事件发 生时编码



1


否则为

< br>0


。降序排序使得


1


成为第 一个水平,是二元变量的目标变量。在回归模


型里把其它类似编码的二元变量按降序排列 对于解释参数估计也是有用的。关闭



Input


Data Source


节点,并存储这些改变。



其它的数据探索



EM


的其它工具可让你进一步探索数据。


工具之一是


Mul tiplot



多图)


节点

< p>
. Multiplot



点建立一系列的直方 图和条形图可使你检查输入变量和二元目标变量的关系。




1.



右击



Multiplot


节点并选择



Run


.


2.



在出现的弹出框里选


Yes



浏览结果


.


通过使用键盘上的


Page Down


,你可以浏览关于该数据的直方图。




从这个直方图你可以知道许多的欺诈贷款是由债务收入比高或者债务收入比未知的购


房者造成的。





2.2


数据划分




了解


Data Partition



数据划分)节点




查看数据划分节点的缺省设置




1.




Data Partition


节点放到框图里


.


2.




Data Partition


节点和




节点连起来


.



3.



打开


Data Partition


节点,或者通过双击节点或者右击鼠标并选择


Open…


.



选择标签左上部的划分方法


.


?



按缺省方式,

EM


在输入数据中抽取简单随机样本并划分为训练数据、验证数据和测


试数据


.


?


< p>
如要进行分层抽样,


选择


Stratified


圆钮并使用


Stratified


标签中的选择项建立各个层



.


?



如要进行用户自定义的抽样,


选择


User Defined


圆钮并使用


User Defined


标签中的选


择项挑选出数据集合中的某个变量,该变量确定划分


.


在启动抽样过程前你可以在标签的左下部分指定一个随机种子。

计算机程序的随机化过


程经常始于某种种子。


如果你在不同 的挖掘流程使用相同的数据集合和相同的种子,你


会得到相同的数据划分。


注意对数据的重新排序会导致数据的不同的顺序,


因此导致不


同的数据划分,这有可能会产生不同的挖掘结果


.


该 标签的右边你可以指定数据划分到训练数据、验证数据和测试数据的百分数


.


划分



HMEQ


数据集合用于建模


.


根据现有的数据创建训练数据和验证数据集合,忽略


测试数据


.


4.



分布设置



Train, Validation,




Test




67, 33,




0.


5.



关闭


Data Partition


节点,选择


Yes



把所做的改动存起来


.


2.3


生成和解释决策树



目标:



学习


EM


可用的决策树模型类型



生成决策树模型



检查模型结果和解释这些结果



理论和实证角度选择决策阈值




要完成第一个框图的第一阶段,


需把一个


T ree


节点和一个


Assessment


节点加到工作区


并连接如下


:



检查决策树的缺省设置


.


1.



双击打开


Tree



节点


.


2.



查看


Variables


标签以确保 所有的变量具有适当的状态、模型作用以及测量水平


.



?



如果变量的模型角色或者测量水平 信息不正确,在这个节点里是不能修改的。


你必须返回到输入数据源(

< br>input data source




节点去修正


.


3.



选择



Basic


.



以前讨论的生成决策树的选择项均在此标签中


.


可用的裂分标准依赖于目标变量的测量水平。


对于二元或者名义目标变量,< /p>


缺省的裂分


标准是


chi- square


检验,显著性水平为


0.2.


如果不用缺省设置,你可以用


entropy


减少


或者


Gini


(基尼数) 减少的方法作为裂分标准。对于有序目标变量,只有


entropy

< br>或者


基尼数方法。对于连续型目标变量,你有两个裂分标准供选择:缺省



F


检验或者方差


减少。



这一标签的其它选择项影响树的生长和大小。按照缺省,只有二元裂分可用,树的最大

< br>深度是


6


个层次,树叶中最小的观测记录数是

< p>
1.


然而,还有一个节点裂分所需要的观


测记录 数的设置。这个数值的缺省值是训练数据里所有的记录数除以


100.


4.



关闭



Tree


节点


.


5.




< /p>


Tree


节点运行框图。右击


Tree< /p>



节点并选择



Run


.


6.



选择弹出框的


Yes



查看结果


.


当查看树节点的结果时,



All


标签处于活动状态,界面展示了后面几个子标签的总结。





从右下角的图形我们知道训练数据 集合最初生成的是


18


个树叶的树,然后根据验证数

< p>
据集合被修剪成有


8


个树叶的树。


左下角的表告诉我们这个


8


个树叶的树在验证数据上< /p>


的精度是


89.02%.


7.



通过选择菜单条


View



?



Tree



查看树


.


以下是树的一部分


.



尽管这棵树应该有8个树叶,但这些树叶并不都能看到。根据缺省,决策树浏览器只显


示3层


.



要修改可浏览的层数,操作如下


:


1.



选择


View



?



Tree Options…


.


2.





Tree depth down


区域键入



6


.


3.



选择



OK


.



4.



检查一下所有8个树叶是否都能看到


.



The colors in the tree ring diagram and the decision tree itself indicate node purity by default.


If the node contains all ones or all zeros, the node is colored red. If the node contains an equal


mix of ones and zeros, it is colored yellow.



You can change the coloring scheme as follows:


1.



Select


Tools



?



Define Colors


.



2.



Select the


Proportion of a target value


radio button.



3.



Select


0


in the Select a target value table. Selecting zero as the target value makes the


leaves with all zeros green and those with no zeros (that is, all ones) red. In other words,


leaves that include only individuals who will default on their loan will be red.


4.



Select


OK


.


Inspect the tree diagram to identify the terminal nodes with a high percentage of bad loans


(colored red) and those with a high percentage of good loans (colored green).


你还可以改变树节点统计量的显示


.


1.



选择



View



?



Statistics…


.



2.



要关闭


Count per class


(每类别的数量)


,右击


Count per class


行的


Select


列。在弹


出菜单里选择


Set Select



?



No


.


3.



同样方法关闭



N in node, Predicted Value, Training Data,


以及



Node ID


行,


你的屏幕


上可以看到更多的树叶


.


4.



选择



OK


.


-


-


-


-


-


-


-


-



本文更新与2021-02-10 16:47,由作者提供,不代表本网站立场,转载请注明出处:https://www.bjmy2z.cn/gaokao/630285.html

使用决策树的预测建模的相关文章