Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed Jan 10, 2019
1 parent 98a68fb commit 04b1e20
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,7 @@
- removed the time-varying component from `AalenAdditiveFitter`. This will return in a future release.
- new `print_summary`
- `weights_col` is added
- `nn_cumulative_hazard` is removed (may add back)


#### 0.16.3
Expand Down
7 changes: 3 additions & 4 deletions lifelines/fitters/aalen_additive_fitter.py
Expand Up @@ -8,13 +8,14 @@
import pandas as pd
from numpy.linalg import LinAlgError
from scipy import stats
from scipy.integrate import trapz

from lifelines.fitters import BaseFitter
from lifelines.utils import (
_get_index,
inv_normal_cdf,
epanechnikov_kernel,
ridge_regression_plus as lr,
ridge_regression as lr,
qth_survival_times,
pass_for_numeric_dtypes_or_raise,
concordance_index,
Expand Down Expand Up @@ -216,9 +217,7 @@ def _fit_model_to_data_batch(self, X, T, E, weights, show_progress):
exits = T == t
deaths = exits & E
try:
R = lr(X, W * deaths, c1=self.coef_penalizer, c2=self.smoothing_penalizer, offset=v, ix=deaths)
V = R[:, :-1]
v = R[:, -1]
v, V = lr(X, W * deaths, c1=self.coef_penalizer, c2=self.smoothing_penalizer, offset=v, ix=deaths)
except LinAlgError:
warnings.warn(
"Linear regression error at index=%d, time=%.3f. Try increasing the coef_penalizer value." % (i, t),
Expand Down
5 changes: 3 additions & 2 deletions lifelines/utils/__init__.py
Expand Up @@ -693,7 +693,7 @@ def significance_codes_as_text():
return "Signif. codes: " + " ".join(["%s '%s'" % (p, significance_code(p)) for p in p_values]) + " 1"


def ridge_regression_plus(X, Y, c1=0.0, c2=0.0, offset=None, ix=None):
def ridge_regression(X, Y, c1=0.0, c2=0.0, offset=None, ix=None):
"""
Also known as Tikhonov regularization. This solves the minimization problem:
Expand Down Expand Up @@ -732,7 +732,8 @@ def ridge_regression_plus(X, Y, c1=0.0, c2=0.0, offset=None, ix=None):
M = np.c_[X.T[:, ix], b]
else:
M = np.c_[X.T, b]
return solve(A, M, assume_a="pos", check_finite=False)
R = solve(A, M, assume_a="pos", check_finite=False)
return R[:, -1], R[:, :-1]


def _smart_search(minimizing_function, n, *args):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_estimation.py
Expand Up @@ -2503,7 +2503,7 @@ def test_cumulative_hazards_versus_R(self, aaf, regression_dataset):
regression_dataset["E"] = 1

aaf.fit(regression_dataset, "T", "E")
actual = aaf.cumulative_hazards_.loc[regression_dataset["T"].max()]
actual = aaf.cumulative_hazards_.iloc[-1]
npt.assert_allclose(actual["baseline"], 2.1675130235, rtol=1e-06)
npt.assert_allclose(actual["var1"], 0.6820086125, rtol=1e-06)
npt.assert_allclose(actual["var2"], -0.0776583514, rtol=1e-06)
Expand Down

0 comments on commit 04b1e20

Please sign in to comment.