SAS中文论坛

 找回密码
 立即注册

扫一扫,访问微社区

查看: 1401|回复: 0
打印 上一主题 下一主题

SAS EM:Variable Selection node(变量选择节点)之二

[复制链接]

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
楼主
 楼主| 发表于 2010-10-22 22:51:42 | 只看该作者

SAS EM:Variable Selection node(变量选择节点)之二

From supersasmacro's blog on Sina

<div>SAS EM:Variable Selection node(变量选择节点)</DIV>
<div><br /></DIV>
<div>运用卡方方式进行变量选择,暨PROC dmsplit(dmsplit过程步)讲解</DIV>
<div><br /></DIV>
<div>SAS EM(Enterprise Miner)企业数据挖掘节点功能详解及代码实现(第七弹)</DIV>
<div><br /></DIV>
<div>本文未经作者允许,请勿转载</DIV>
<div><br /></DIV>
<div>
许多数据挖掘的数据集都含有数百个潜在的独立变量作为模型的输入变量,通过变量选择节点可以去除与目标不相关的变量来减少输入的变量。通常使用的方法是利用线性模式用选择的输入变量来预测目标变量,然后保留信息含量较大的输入变量,举例来说,使用最小平方(Least
Squares)、Logistic的回归方法或是其他分析的方法,在这里你可以先用使用 R-square(R2)或是
Chi-square(卡方)的方法来选择变量。</DIV>
<div>&nbsp;<a href="http://blog.photo.sina.com.cn/showpic.html#url=http://static11.photo.sina.com.cn/orignal/5d3b177cg8cd535a8039a" TARGET="_blank"><img SRC="http://static11.photo.sina.com.cn/middle/5d3b177cg8cd535a8039a&amp;690" WIDTH="500" HEIGHT="300" /></A></DIV>
<br />
<a href="http://blog.photo.sina.com.cn/showpic.html#url=http://static3.photo.sina.com.cn/orignal/5d3b177cg8cd535c68472" TARGET="_blank"><img SRC="http://static3.photo.sina.com.cn/middle/5d3b177cg8cd535c68472&amp;690" WIDTH="690" HEIGHT="193" /></A>&nbsp;<br />
<div>对于目标变量是分类型的模型,变量选择可以提供三种方式,其中包括 R2,卡方和两种方法的结合。目标变量是连续型的模型只要 R2
方法可以选择。在两种方法的结合中,变量只有同时被 R2
和卡方选择的时候才能作为输入进入该方法。实际上,两种方法结合的方法可以避免过度拟合情况,但是考虑到变量选择方法只在训练数据上进行,这种方法就显得有点不完善。结果会出现选出的变量可能不适合其他预留的数据。</DIV>
<div>&nbsp;<a href="http://blog.photo.sina.com.cn/showpic.html#url=http://static3.photo.sina.com.cn/orignal/5d3b177cg8cd53929d782" TARGET="_blank"><img SRC="http://static3.photo.sina.com.cn/middle/5d3b177cg8cd53929d782&amp;690" WIDTH="647" HEIGHT="240" /></A></DIV>
<br />
<div>
在卡方模式下,用户可以指定三种额外选项:其中一个是用来决定把连续型变量分成多少个相同的箱;另一个是控制在运行二项分割时的迭代次数;最后一个是指定一个用来决定预测变量是否保留的阀值。默认设置下,阀值为
3.84,它对应于自由度为 1
的卡方分布中的显著水平α=0.05。阀值不是用来判断变量最终是否重要,而是用作判断的标尺。任何没有满足最小显著水平要求的变量都会被排除。</DIV>
<div>&nbsp;<a href="http://blog.photo.sina.com.cn/showpic.html#url=http://static2.photo.sina.com.cn/orignal/5d3b177cg8cd53b6716b1" TARGET="_blank"><img SRC="http://static2.photo.sina.com.cn/middle/5d3b177cg8cd53b6716b1&amp;690" WIDTH="315" HEIGHT="136" /></A></DIV>
<br />
<div>再删掉缺失值超过未百分比的变量,以及层级变量。</DIV>
<div>&nbsp;<a href="http://blog.photo.sina.com.cn/showpic.html#url=http://static8.photo.sina.com.cn/orignal/5d3b177cg8cd53c58dcd7" TARGET="_blank"><img SRC="http://static8.photo.sina.com.cn/middle/5d3b177cg8cd53c58dcd7&amp;690" WIDTH="690" HEIGHT="109" /></A></DIV>
<br />
<div>
从数据挖掘定义上看,大多数数据挖掘应用要有大量的数据。但是随着数据量的增加,特定的检验统计指标就会越显著。换句话说,就是在给定样本量差别不显著,而在更大的样本量上就会变得显著。很多情况下,数据挖掘时通常取
α=0.05 可能会使过多的变量进入模型。尝试把 α
设置为不同的值可以使分析员精确的控制保留变量的个数。在变量还需进一步选择的情况下,可以考虑保留一些不太重要的变量直到进入下一个变量选择阶段。然而,如果这个节点用于选择进入最终模型的变量,那么就需要慎重考虑这些不太重要的变量的实际重要性了,评估它们是否要包含在最终的模型中。&nbsp;</DIV>
<div>
至于卡方的其他设置,增加迭代次数可能获得较好的拟合,但是会消耗大量的处理时间,而减少迭代次数可能在一定程度上影响性能,但可以节约大量时间。在数据挖掘中,记录数以及变量数可能会极其大,因此减小循环数和/或者增大阀值,可以加快处理时间。同样,减少把分箱数控制在默认的
50 箱下也可能提高运算速度。</DIV>
<div><br /></DIV>
<div>%let DM_SEED=12345;</DIV>
<div><br /></DIV>
<div>data EMDATA.VIEW_6HE / view=EMDATA.VIEW_6HE;</DIV>
<div>&nbsp;set EMSAMPLE.HMEQ;</DIV>
<div>run;</DIV>
<div><br /></DIV>
<div>data EMPROJ.SMP_VIGA(label="Sample of
EMDATA.VIEW_4O9.");</DIV>
<div>&nbsp;set EMDATA.VIEW_6HE;</DIV>
<div>&nbsp;&nbsp; &nbsp; drop
_sample_count_;</DIV>
<div>&nbsp;&nbsp; &nbsp; if
_sample_count_ &lt; 2000 then do;</DIV>
<div>&nbsp;&nbsp; &nbsp;
&nbsp; &nbsp;if ranuni(12345) *(5960 + 1 -
_N_ ) &lt; = ( 2000 - _sample_count_) then do ;</DIV>
<div>&nbsp;&nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;
_sample_count_ + 1;</DIV>
<div>&nbsp;&nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;
output;</DIV>
<div>&nbsp;&nbsp; &nbsp;
&nbsp; &nbsp;end;</DIV>
<div>&nbsp;&nbsp; &nbsp;
end;</DIV>
<div>run;</DIV>
<div>quit;</DIV>
<div><br /></DIV>
<div>proc dmdb data = EMDATA.VIEW_6HE&nbsp;</DIV>
<div>&nbsp;&nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;out =
_null_&nbsp;</DIV>
<div>&nbsp;&nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;dmdbcat=
EMPROJ.dm_DGM00000</DIV>
<div>&nbsp;&nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;normlen=32
maxlevel=513;</DIV>
<div>&nbsp;&nbsp; &nbsp; class
BAD(Desc) REASON(Asc) JOB(Asc);</DIV>
<div>&nbsp;&nbsp; &nbsp; var
LOAN MORTDUE VALUE YOJ DEROG</DIV>
<div>&nbsp;&nbsp; &nbsp;
&nbsp; &nbsp; DELINQ CLAGE NINQ CLNO
DEBTINC;</DIV>
<div>&nbsp;&nbsp; &nbsp; target
BAD;</DIV>
<div>run;</DIV>
<div><br /></DIV>
<div>* Create data view with dmdb name;</DIV>
<div>data EMDATA.dm_DGM00000 / view=EMDATA.dm_DGM00000;</DIV>
<div>&nbsp;set EMDATA.VIEW_6HE;</DIV>
<div>run;</DIV>
<div><br /></DIV>
<div>* dmsplit过程步语法如下:;</DIV>
<div>PROC DMSPLIT &lt;option(s)&gt;;</DIV>
<div>FREQ variable;</DIV>
<div>TARGET variable;</DIV>
<div>VARIABLE variable-list;</DIV>
<div>WEIGHT variable;</DIV>
<div>这里,对其选项进行说明:</DIV>
<div>BINS:将变量分为多少个箱</DIV>
<div>CHISQ:最小协方差</DIV>
<div>OUTVARS:变量分割结果的输出</DIV>
<div>PASSES:最多分割的步数</DIV>
<div>PRINT | NOPRINT:是否打印</DIV>
<div><br /></DIV>
<div>proc dmsplit data=EMDATA.VIEW_6HE&nbsp;</DIV>
<div>&nbsp;&nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;
&nbsp;
dmdbcat=EMPROJ.dm_DGM00000&nbsp;</DIV>
<div>&nbsp;&nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;
&nbsp; bins=50 chisq=3.84 passes=6</DIV>
<div>&nbsp;&nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;
&nbsp; outvars = EMPROJ.OUTVMEFV;</DIV>
<div>&nbsp;&nbsp; &nbsp; var
LOAN MORTDUE VALUE REASON JOB</DIV>
<div>&nbsp;&nbsp; &nbsp;
&nbsp; &nbsp; YOJ DEROG DELINQ CLAGE
NINQ</DIV>
<div>&nbsp;&nbsp; &nbsp; CLNO
DEBTINC;</DIV>
<div>&nbsp;&nbsp; &nbsp; target
BAD;</DIV>
<div>run;</DIV>
<div>输出如下:</DIV>
<div>&nbsp;<a href="http://blog.photo.sina.com.cn/showpic.html#url=http://static5.photo.sina.com.cn/orignal/5d3b177cg8cd53e9d7a84" TARGET="_blank"><img SRC="http://static5.photo.sina.com.cn/middle/5d3b177cg8cd53e9d7a84&amp;690" WIDTH="507" HEIGHT="561" /></A></DIV>
<br />
<div>我们可以依照此结果,画出决策树。例如对于node
1,其parent为0,即它为母结点,它要分割的变量为DELINQ,其分割点为0.6;分割后得到node2和node3,因为其parent为1,然后我们再加node2和node3进行分割,就得到我们常见的决策树图了。</DIV>
<div><br /></DIV>
<div>proc split dmdbcat=EMPROJ.dm_DGM00000&nbsp;</DIV>
<div>&nbsp;&nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;
indmsplit</DIV>
<div>&nbsp;&nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;
subtree=largest&nbsp;</DIV>
<div>&nbsp;&nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;
outtree=EMPROJ.OUTTWA1U;</DIV>
<div>run;</DIV>
<div>对于SPLIT过程步,我们将在以后的章节进行讲解。</DIV>
<div><br /></DIV>
<div>查看EMPROJ.OUTVMEFV数据集结果:</DIV>
<div>&nbsp;<a href="http://blog.photo.sina.com.cn/showpic.html#url=http://static4.photo.sina.com.cn/orignal/5d3b177cg8cd543442ca3" TARGET="_blank"><img SRC="http://static4.photo.sina.com.cn/middle/5d3b177cg8cd543442ca3&amp;690" WIDTH="690" HEIGHT="423" /></A></DIV>
<div>这里,_SUMMART的七个变量即为DMSPLIT过程步最终选择的变量</DIV>
<div><br /></DIV>
<div><br /></DIV>
<div><br /></DIV>
<div>本文用到的SAS数据集为hmeq.sas7bdat,其下载地址:</DIV>
<div><!-- m --><a class="postlink" href="http://ishare.iask.sina.com.cn/f/8641129.html">http://ishare.iask.sina.com.cn/f/8641129.html</a><!-- m --></DIV>
<div>本系列全部数据下载地址:</DIV>
<div><!-- m --><a class="postlink" href="http://iask.sina.com.cn/u/1564153724/ish">http://iask.sina.com.cn/u/1564153724/ish</a><!-- m --></DIV>
<div><br /></DIV><div style="border-top: 1px solid rgb(203, 217, 217); padding-top: 20px; padding-bottom: 10px;">
<p><br><a href="http://move.blog.sina.com.cn/admin/blogmove/blogmove_msn.php" target="_blank">MSN空间完美搬家到新浪博客!</a></p></div>
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|SAS中文论坛  

GMT+8, 2026-2-3 20:03 , Processed in 0.066121 second(s), 20 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表