-
-
Notifications
You must be signed in to change notification settings - Fork 562
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fixes and perf improvements for 0.16.2 * bump version * creating test for single vs batch, and adding perf script * remove pdb * fix test
- Loading branch information
1 parent
ca9673e
commit 0063469
Showing
9 changed files
with
244 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
__version__ = "0.16.1" | ||
__version__ = "0.16.2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from time import time | ||
import pandas as pd | ||
import numpy as np | ||
from lifelines.datasets import load_rossi | ||
from lifelines import CoxPHFitter | ||
import statsmodels.api as sm | ||
|
||
# This compares the batch algorithm (in CTV) vs the single iteration algorithm (original in CPH) | ||
# N vs (% ties == unique(T) / N) | ||
|
||
|
||
ROSSI_ROWS = 432 | ||
results = {} | ||
|
||
|
||
for n_copies in [1, 2, 4, 6, 8, 10, 12, 14]: | ||
|
||
# lower percents means more ties. | ||
# original rossi dataset has 0.113 | ||
for fraction in np.linspace(0.01, 0.30, 10): | ||
print(n_copies, fraction) | ||
|
||
df = pd.concat([load_rossi()] * n_copies) | ||
n_unique_durations = int(df.shape[0] * fraction) + 1 | ||
unique_durations = np.round(np.random.exponential(10, size=n_unique_durations), 5) | ||
|
||
df["week"] = np.tile(unique_durations, int(np.ceil(1 / fraction)))[: df.shape[0]] | ||
|
||
cph_batch = CoxPHFitter() | ||
start_time = time() | ||
cph_batch.fit(df, "week", "arrest", batch_mode=True) | ||
batch_time = time() - start_time | ||
|
||
cph_single = CoxPHFitter() | ||
start_time = time() | ||
cph_single.fit(df, "week", "arrest", batch_mode=False) | ||
single_time = time() - start_time | ||
|
||
print({"batch": batch_time, "single": single_time}) | ||
results[(n_copies * ROSSI_ROWS, fraction)] = {"batch": batch_time, "single": single_time} | ||
|
||
results = pd.DataFrame(results).T.sort_index() | ||
results["ratio"] = results["batch"] / results["single"] | ||
print(results) | ||
|
||
results = results.reset_index() | ||
results = results.rename(columns={"level_0": "N", "level_1": "frac"}) | ||
|
||
|
||
results["N * frac"] = results["N"] * results["frac"] | ||
|
||
X = results[["N", "frac", "N * frac"]] | ||
X = sm.add_constant(X) | ||
|
||
Y = results["ratio"] | ||
|
||
|
||
model = sm.OLS(Y, X).fit() | ||
model.summary() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.