|
15 | 15 | # Let's first generate synthetic data on which to run the Cox estimator, |
16 | 16 | # using ``skglm`` data utils. |
17 | 17 | # |
18 | | -import warnings |
19 | | -import time |
20 | | -from lifelines import CoxPHFitter |
21 | | -import pandas as pd |
22 | | -import numpy as np |
23 | | -from skglm.solvers import ProxNewton |
24 | | -from skglm.penalties import L1 |
25 | | -from skglm.datafits import Cox |
26 | | -import matplotlib.pyplot as plt |
| 18 | + |
27 | 19 | from skglm.utils.data import make_dummy_survival_data |
28 | 20 |
|
29 | 21 | n_samples, n_features = 500, 100 |
|
43 | 35 | # * ``s`` indicates the observations censorship and follows a Bernoulli(0.5) distribution |
44 | 36 | # |
45 | 37 | # Let's inspect the data quickly: |
| 38 | +import matplotlib.pyplot as plt |
46 | 39 |
|
47 | 40 | fig, axes = plt.subplots( |
48 | 41 | 1, 3, |
|
67 | 60 | # Todo so, we need to combine a Cox datafit and a :math:`\ell_1` penalty |
68 | 61 | # and solve the resulting problem using skglm Proximal Newton solver ``ProxNewton``. |
69 | 62 | # We set the intensity of the :math:`\ell_1` regularization to ``alpha=1e-2``. |
70 | | - |
| 63 | +from skglm.penalties import L1 |
| 64 | +from skglm.datafits import Cox |
| 65 | +from skglm.solvers import ProxNewton |
71 | 66 |
|
72 | 67 | # regularization intensity |
73 | 68 | alpha = 1e-2 |
|
94 | 89 | # %% |
95 | 90 | # Let's solve the problem with ``lifelines`` through its ``CoxPHFitter`` |
96 | 91 | # estimator and compare the objectives found by the two packages. |
| 92 | +import numpy as np |
| 93 | +import pandas as pd |
| 94 | +from lifelines import CoxPHFitter |
97 | 95 |
|
98 | 96 | # format data |
99 | 97 | stacked_y_X = np.hstack((y, X)) |
|
127 | 125 | # let's compare their execution time. To get the evolution of the suboptimality |
128 | 126 | # (objective - optimal objective) we run both estimators with increasing number of |
129 | 127 | # iterations. |
| 128 | +import time |
| 129 | +import warnings |
130 | 130 |
|
131 | 131 | warnings.filterwarnings('ignore') |
132 | 132 |
|
|
0 commit comments