Skip to content

Instantly share code, notes, and snippets.

View alonsosilvaallende's full-sized avatar

Alonso Silva Allende alonsosilvaallende

View GitHub Profile
@alonsosilvaallende
alonsosilvaallende / performance_random_survival_forests.ipynb
Last active September 27, 2019 15:31
Performance_Random_Survival_Forests.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@alonsosilvaallende
alonsosilvaallende / PerfectPrediction.py
Last active October 8, 2019 09:58
Perfect prediction
from lifelines.utils import concordance_index
names = ['Alice', 'Bob', 'Carol', 'Dave', 'Eve']
events = [1, 2, 3, 4, 5]
preds = [1, 2, 3, 4, 5]
df = pd.DataFrame(data={'Churn times': events, 'Predictions': preds}, index=names)
print(df)
print(f'Concordance index: {concordance_index(events, preds)}')
@alonsosilvaallende
alonsosilvaallende / PerfectOrdering.py
Last active October 8, 2019 09:59
Perfect ordering of events
from lifelines.utils import concordance_index
names = ['Alice', 'Bob', 'Carol', 'Dave', 'Eve']
events = [1, 2, 3, 4, 5]
preds = [2, 3, 5, 8, 14]
df = pd.DataFrame(data={'Churn times': events, 'Predictions': preds}, index=names)
print(df)
print(f'Concordance index: {concordance_index(events, preds)}')
@alonsosilvaallende
alonsosilvaallende / PerfectLog.py
Last active October 8, 2019 10:01
Perfect ordering with logarithm
from lifelines.utils import concordance_index
names = ['Alice', 'Bob', 'Carol', 'Dave', 'Eve']
events = [1, 2, 3, 4, 5]
preds = np.log(events)
df = pd.DataFrame(data={'Churn times': events, 'Predictions': preds}, index=names)
print(df)
print(f'Concordance index: {concordance_index(events, preds)}')
@alonsosilvaallende
alonsosilvaallende / PerfectlyWrong.py
Last active October 8, 2019 10:03
Perfectly wrong ordering
from lifelines.utils import concordance_index
names = ['Alice', 'Bob', 'Carol', 'Dave', 'Eve']
events = [1, 2, 3, 4, 5]
preds = [5, 4, 3, 2, 1]
df = pd.DataFrame(data={'Churn times': events, 'Predictions': preds}, index=names)
print(df)
print(f'Concordance index: {concordance_index(events, preds)}')
@alonsosilvaallende
alonsosilvaallende / PerfectlyWrongInverse.py
Last active October 8, 2019 10:04
Perfectly wrong prediction with the inverse function
from lifelines.utils import concordance_index
names = ['Alice', 'Bob', 'Carol', 'Dave', 'Eve']
events = [1, 2, 3, 4, 5]
preds = [1/event for event in events]
df = pd.DataFrame(data={'Churn dates': events, 'Predictions': preds}, index=names)
print(df)
print(f'Concordance index: {concordance_index(events, preds)}')
@alonsosilvaallende
alonsosilvaallende / InstallLifelines
Last active October 8, 2019 08:06
Install Lifelines
!pip install lifelines
from lifelines.utils import concordance_index
names = ['Alice', 'Bob', 'Carol', 'Dave', 'Eve']
events = [1, 2, 3, 4, 5]
preds = [3, 2, 1, 5, 4]
df = pd.DataFrame(data={'Churn times': events, 'Predictions': preds}, index=names)
print(df)
print(f'Concordance index: {concordance_index(events, preds)}')
from lifelines.utils import concordance_index
names = ['Alice', 'Bob', 'Carol', 'Dave', 'Eve']
events = [1, 2, 3, 4, 5]
preds = [1, 2, 3, 4, 4]
df = pd.DataFrame(data={'Churn times': events, 'Predictions': preds}, index=names)
print(df)
print(f'Concordance index: {concordance_index(events, preds)}')
from lifelines.utils import concordance_index
names = ['Alice', 'Bob', 'Carol', 'Dave', 'Eve']
times = [1, 2, 3, 4, 5]
preds = [1, 2, 3, 5, 4]
event_obs = [True, True, False, True, True]
df = pd.DataFrame(data={'Times': times, 'Predictions': preds, 'Event observed?': event_obs}, index=names)
print(df)
print(f'Concordance index: {concordance_index(events, preds, event_obs)}')