Skip to content

Commit

Permalink
Merge d3fb550 into 0553483
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed Sep 2, 2019
2 parents 0553483 + d3fb550 commit 448ee36
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 6 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ env:
matrix:
- export PANDAS_VERSION=0.23.4 && export NUMPY_VERSION=1.17.0
- export PANDAS_VERSION=0.24.1 && export NUMPY_VERSION=1.17.0
- export PANDAS_VERSION=0.25.0 && export NUMPY_VERSION=1.17.0
- export NUMPY_VERSION=1.16.4 && export PANDAS_VERSION=0.25.0
- export NUMPY_VERSION=1.15.4 && export PANDAS_VERSION=0.25.0
- export NUMPY_VERSION=1.17.0 && export PANDAS_VERSION=0.25.0
- export PANDAS_VERSION=0.25.1 && export NUMPY_VERSION=1.17.0
- export NUMPY_VERSION=1.16.4 && export PANDAS_VERSION=0.25.1
- export NUMPY_VERSION=1.15.4 && export PANDAS_VERSION=0.25.1
- export NUMPY_VERSION=1.17.0 && export PANDAS_VERSION=0.25.1
before_install:
- ls
# - sudo apt-get update
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
### Changelog


#### 0.22.4

##### New features
- Some performance improvements to regression models.

##### Bug fixes
- Fixed issue where `concordance_index` would never exit if NaNs in dataset.


#### 0.22.3

##### New features
Expand Down
2 changes: 0 additions & 2 deletions lifelines/fitters/cox_time_varying_fitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ class CoxTimeVaryingFitter(BaseFitter):
the strata provided
standard_errors_: Series
the standard errors of the estimates
score_: float
the concordance index of the model.
baseline_cumulative_hazard_: DataFrame
baseline_survival_: DataFrame
"""
Expand Down
5 changes: 5 additions & 0 deletions lifelines/utils/concordance.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,9 @@ def _preprocess_scoring_data(event_times, predicted_scores, event_observed):
if event_observed.shape != event_times.shape:
raise ValueError("Observed events must be 1-dimensional of same length as event times")

# check for NaNs
for a in [event_times, predicted_scores, event_observed]:
if np.isnan(a).any():
raise ValueError("NaNs detected in inputs, please correct or drop.")

return event_times, predicted_scores, event_observed
28 changes: 28 additions & 0 deletions tests/test_estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1392,6 +1392,34 @@ def test_BHF_fit_when_KMF_throws_an_error(self):
bfh.fit(observations, entry=births)


class TestParametricRegressionFitter:
@pytest.fixture
def rossi(self):
rossi = load_rossi()
rossi["_int"] = 1.0
return rossi

def test_custom_weibull_model_gives_the_same_data_as_implemented_weibull_model(self, rossi):
class CustomWeibull(ParametricRegressionFitter):

_fitted_parameter_names = ["lambda_", "rho_"]

def _cumulative_hazard(self, params, T, Xs):
lambda_ = anp.exp(anp.dot(Xs["lambda_"], params["lambda_"]))
rho_ = anp.exp(anp.dot(Xs["rho_"], params["rho_"]))

return (T / lambda_) ** rho_

cb = CustomWeibull()
wf = WeibullAFTFitter(fit_intercept=False)

cb.fit(rossi, "week", "arrest", regressors={"lambda_": rossi.columns, "rho_": ["_int"]})
wf.fit(rossi, "week", "arrest")

assert_frame_equal(cb.summary.loc["lambda_"], wf.summary.loc["lambda_"], check_less_precise=2)
npt.assert_allclose(cb.log_likelihood_, wf.log_likelihood_)


class TestRegressionFitters:
@pytest.fixture
def rossi(self):
Expand Down

0 comments on commit 448ee36

Please sign in to comment.