标题: Stochastic Gradient Decending Logistic Regression in SAS [打印本页] 作者: shiyiming 时间: 2012-5-24 21:50 标题: Stochastic Gradient Decending Logistic Regression in SAS From oloolo's blog on SasProgramming
<p><a href="http://feedads.g.doubleclick.net/~a/PjvzRIUQaqOILxxFQcDQHXpxHU8/0/da"><img src="http://feedads.g.doubleclick.net/~a/PjvzRIUQaqOILxxFQcDQHXpxHU8/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/PjvzRIUQaqOILxxFQcDQHXpxHU8/1/da"><img src="http://feedads.g.doubleclick.net/~a/PjvzRIUQaqOILxxFQcDQHXpxHU8/1/di" border="0" ismap="true"></img></a></p>Test the Stochastic Gradient Decending Logistic Regression in SAS. The logic and code follows the code piece of Ravi Varadhan, Ph.D from this <a href="http://r.789695.n4.nabble.com/Stochastic-Gradient-Ascent-for-logistic-regression-td884272.html" target="_blank"><strong><em>discussion</em></strong> </a>of R Help. The blog <a href="http://sasdiehard.blogspot.com/" target="_blank"><strong><em>SAS Die Hard</em></strong></a> also has a post about SGD Logistic Regression in SAS.<br />
<br />
<br />
<br />
<pre style="background-color: #ebebeb; border-bottom: #999999 1px dashed; border-left: #999999 1px dashed; border-right: #999999 1px dashed; border-top: #999999 1px dashed; color: #000001; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 100%;"><code>
data temp;
infile foo length=len;
input low age lwt race smoke ptl ht ui ftv bwt;
put low age lwt race smoke ptl ht ui ftv bwt;
if _n_>1;
run;
proc standard data=temp out=temp mean=0 std=1;
var age lwt smoke ht ui;
run;
proc contents data=temp out=vars(keep=varnum name type) noprint; run;
proc sql noprint;
select name into :covars separated by " "
from vars
where substr(name, 1, 1)="x"
;
select cats("b_", name) into :covars2 separated by " "
from vars
where substr(name, 1, 1)="x"
;
select count(*)+1 into :nparms
from vars
where substr(name, 1, 1)="x"
;
quit;
%put &covars2;
The SAS macro is a demonstration of an implementation of logistic
regression modelstrained by Stochastic Gradient Decent (SGD).This
program reads a training set specified as &dsn_in, trains a logistic
regression model, and outputs the estimated coefficients to &outest.
Example usage:
The following topics are not covered for simplicity:
- bias term
- regularization
- multiclass logistic regression (maximum entropy model)
- calibration of learning rate
<i>Distributed under GNU Affero General Public License version 3. This
program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, only version 3 of the
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.