-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathexample_cox.py
48 lines (36 loc) · 1.04 KB
/
example_cox.py
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
# Import relevant modules and setup for calling glmnet
import sys
sys.path.append('../test')
sys.path.append('../lib')
import scipy
import importlib
import matplotlib.pyplot as plt
import glmnet
import glmnetPlot
import glmnetPrint
import glmnetCoef
import glmnetPredict
import cvglmnet
import cvglmnetCoef
import cvglmnetPlot
import cvglmnetPredict
importlib.reload(glmnet)
importlib.reload(glmnetPlot)
importlib.reload(glmnetPrint)
importlib.reload(glmnetCoef)
importlib.reload(glmnetPredict)
importlib.reload(cvglmnet)
importlib.reload(cvglmnetCoef)
importlib.reload(cvglmnetPlot)
importlib.reload(cvglmnetPredict)
# parameters
baseDataDir= '../data/'
# load data
x = scipy.loadtxt(baseDataDir + 'CoxExampleX.dat', dtype = scipy.float64, delimiter = ',')
y = scipy.loadtxt(baseDataDir + 'CoxExampleY.dat', dtype = scipy.float64, delimiter = ',')
print(y[0:5, :])
# call glmnet
fit = glmnet.glmnet(x = x.copy(), y = y.copy(), family = 'cox')
glmnetPlot.glmnetPlot(fit)
c = glmnetCoef.glmnetCoef(fit, s = scipy.float64([0.05]))
print(c)