-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathk-fold.sas
More file actions
111 lines (92 loc) · 1.71 KB
/
k-fold.sas
File metadata and controls
111 lines (92 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*Import dataset*/
proc import out = dataset
datafile = "C:\Users\Sasiwut.Chaiyadecha\Desktop\Python\titanic.csv"
DBMS = csv
replace;
getnames = yes;
quit;
/*Keep only numberic variables*/
data dataset;
set dataset;
keep
Survived
Pclass
Age
SibSp
Parch
Fare
;
run;
/*Fill missing values*/
proc stdize data = dataset reponly method = mean out = dataset;
var Age;
quit;
/*Results dataset*/
data KFold_results;
set _null_;
run;
/*Macro K-Fold Cross validation*/
%macro KFold(data, k);
proc surveyselect data = &data groups = &k out = fold;
quit;
%do i = 1 %to &k;
data train test;
set fold;
if groupid ne &i then output train;
if groupid eq &i then output test;
run;
/*Logistic model*/
proc logistic data = train descending;
model Survived =
Pclass
Age
SibSp
Parch
Fare;
roc;
ods output rocassociation = auc;
score data = test out = valset;
quit;
/*Model performance*/
data auc;
set auc;
where RocModel = "Model";
keep Area;
rename Area = AUCTrain;
run;
data auc;
set auc;
GINITrain = 2 * AUCTrain - 1;
run;
/*Testing set*/
proc npar1way wilcoxon data= valset;
class Survived;
var p_1;
ods output WilcoxonScores = WilcoxonScore;
quit;
data auc_test;
set WilcoxonScore;
if Class = 1 then absscore = abs(ExpectedSum - SumOfScores);
run;
proc sql;
create table auc_test as select exp(sum(log(N))) as N, sum(absscore) as absscore
from auc_test;
quit;
data auc_test;
set auc_test;
d = absscore / N;
AUCTest = d + 0.5;
GINITest = d * 2;
keep AUCTest GINITest;
run;
data auc;
merge auc auc_test;
run;
/*Append table*/
data KFold_results;
set KFold_results auc;
run;
%end;
%mend;
/*Execute K-Fold Macro*/
%KFold(dataset, 5);