Skip to content

Instantly share code, notes, and snippets.

id entage follow pd fate fh
1 30 14.863791465759277 0 0 0
2 45 24.16974639892578 0 0 0
3 35 23.32375144958496 0 0 0
4 47 17.4757022857666 0 0 0
5 30 28.43805694580078 1 0 0
6 44 26.376455307006836 1 0 0
7 50 28.331279754638672 1 0 0
8 47 29.3223819732666 0 0 0
9 39 27.299110412597656 1 0 0
@sebp
sebp / export.py
Created April 25, 2020 13:56
Print a fitted SurvivalTree from scikit-survival.
"""
This module defines export functions for survival trees.
It is based on the sklearn.tree.export module.
"""
# Authors: Gilles Louppe <g.louppe@gmail.com>
# Peter Prettenhofer <peter.prettenhofer@gmail.com>
# Brian Holt <bdholt1@gmail.com>
# Noel Dawe <noel@dawe.me>
@sebp
sebp / coefficient_rescaler.py
Created March 28, 2019 14:05
Inverse transform of coefficients of a linear model fit to standardized data with zero mean and unit variance.
import numpy as np
class CoefficientRescaler:
"""Inverse transform of coefficients of a linear model.
Parameters
==========
scalar_mean : ndarray, shape=(n_features,)
Feature-wise mean.
@sebp
sebp / missing_values.py
Created March 20, 2019 14:01
Plot missing values.
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns
from matplotlib.backends.backend_pdf import PdfPages
def index_to_binary_matrix(index):
return index.to_series().apply(lambda x: pd.Series(map(int, x.split(":")), name=x))
@sebp
sebp / simulation.r
Created August 17, 2018 18:53
Simulation study demonstrating performance of logistic regression in the presence of non-linear effects
# simulation study related to https://stats.stackexchange.com/questions/362194/data-how-smart-are-models-is-my-dummy-redundant
library(ROCR)
gen.features <- function(n.samples) {
age <- runif(n.samples, min=6, max=89)
sex <- factor(rbinom(n.samples, 1, 0.5), c(0, 1), c("male", "female"))
data <- data.frame(age, sex)
return(data)
}
@sebp
sebp / coxnet-gridsearch.ipynb
Created June 9, 2018 19:39
GridSearchCV example to select hyper-parameters of CoxnetSurvivalAnalysis
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@sebp
sebp / python-scientific-computing.md
Last active March 14, 2024 02:40
Overview of Python Packages for Scientific Computing
@sebp
sebp / pymc3-bayesian-cor.py
Last active August 14, 2019 15:00
Bayesian correlation coefficient using PyMC3
from theano.printing import Print
import pymc3 as pm
import numpy as np
import theano.tensor as T
def covariance(sigma, rho):
C = T.fill_diagonal(T.alloc(rho, 2, 2), 1.)
S = T.diag(sigma)
M = S.dot(C).dot(S)