Code Documentation
skfibers.fibers module
- class skfibers.fibers.FIBERS(outcome_label='Duration', outcome_type='survival', iterations=100, pop_size=50, tournament_prop=0.2, crossover_prob=0.5, min_mutation_prob=0.1, max_mutation_prob=0.3, merge_prob=0.1, new_gen=1.0, elitism=0.1, diversity_pressure=3, min_bin_size=1, max_bin_size=None, max_bin_init_size=10, fitness_metric='log_rank', log_rank_weighting=None, censor_label='Censoring', group_strata_min=0.2, penalty=0.5, group_thresh=None, min_thresh=0, max_thresh=5, int_thresh=True, thresh_evolve_prob=0.5, manual_bin_init=None, covariates=None, pop_clean=None, report=None, random_seed=None, verbose=False)[source]
Bases:
BaseEstimator,TransformerMixinA Scikit-Learn compatible implementation of the FIBERS Algorithm.
- Parameters:
outcome_label – label indicating the outcome column in the dataset (e.g. ‘SurvivalTime’, ‘Class’)
outcome_type – defines the type of outcome in the dataset [‘survival’,’class’]
iterations – the number of evolutionary cycles FIBERS will run
pop_size – the maximum bin population size
tournament_prop – the proportion of the popultion randomly selected for each parent pair selection
crossover_prob – the probability of each specified feature in a pair of offspring bins to swap between bins
min_mutation_prob – the minimum probability of further offspring bin modification (i.e. feature addition, removal or swap)
max_mutation_prob – the maximum probability of further offspring bin modification (i.e. feature addition, removal or swap)
merge_prob – the probability of two parent bins merging to create a single novel offspring, separate from mutation and crossover
new_gen – proportion that determines the number of offspring generated each iteration based new_gen*pop_size
elitism – proportion of pop_size that is protected from deletion each generation
diversity_pressure – number of bin similarity clusters used to drive bin deletion by maintaining bin diversity
min_bin_size – minimum number of features to be specified within a bin
max_bin_size – maximum number of features to be specified within a bin
max_bin_init_size – maximum number of features within initialized bins
fitness_metric – the pre-fitness metric used by FIBERS to evaluate candidate bins [‘log_rank’,’residuals’,’log_rank_residuals’]
log_rank_weighting – an optional weighting of the log-rank test [‘wilcoxon’,’tarone-ware’,’peto’,’fleming-harrington’]
- Parameters:
censor_label – label indicating the censoring column in the datasets (e.g. ‘Censoring’)
group_strata_min – the minimum cuttoff for group-strata sizes (instance count) below which bins have pre-fitness penalizaiton applied
penalty – the penalty multiplier applied to the pre-fitness of bins that go beneith the group_strata_min
group_thresh – the bin sum (e.g. mismatch count) for an instance over which that instance is assigned to the above threshold group
- Parameters:
min_thresh – for adaptive bin thresholding - the minimum group_thresh allowed
max_thresh – for adaptive bin thresholding - the maximum group_thresh allowed
int_thresh – boolean indicating that adaptive bin thresholds are limited to positive intergers
thresh_evolve_prob – probability that adaptive bin thresholding will evolve vs. be selected for the bin deterministically
- Parameters:
manual_bin_init – a dataframe object including a FIBERS formatted bin population for bin initialization
- Parameters:
covariates – list of feature names in the data to be treated as covariates (not included in binning)
- Parameters:
pop_clean – optional bin population cleanup phase
report – list of integers, indicating iterations where the population will be printed out for viewing
random_seed – the seed value needed to generate a random number
verbose – Boolean flag to run in ‘verbose’ mode - display run details
- fit(x, y=None)[source]
Scikit-learn required function for supervised training of FIBERS
- Parameters:
x – array-like {n_samples, n_features} training instances. ALL INSTANCE ATTRIBUTES MUST BE >0 NUMERIC NOT NAN OR OTHER TYPE, and can include ‘covariates’ OR array-like dataframe {n_samples, n_features} training instances that can include ‘covariates’ and with column name as given by outcome_label and censor_label when y=None. ALL INSTANCE ATTRIBUTES MUST BE >0 NUMERIC NOT NAN OR OTHER TYPE
y – None or list of list/tuples with (censoring, duration) {n_samples, 2} labels. ALL INSTANCE OUTCOMES MUST BE NUMERIC NOT NAN OR OTHER TYPE
- Returns:
self
- get_bin_groups(x, y=None, bin_index=0)[source]
Function for FIBERS that returns the variables needed to construct survival curves for the two instance groups defined by a given bin (low_outcome, high_outcome, low_censor, high_censor)
- Parameters:
x – array-like {n_samples, n_features} training instances. ALL INSTANCE ATTRIBUTES MUST BE >0 NUMERIC NOT NAN OR OTHER TYPE, and can include ‘covariates’ OR array-like dataframe {n_samples, n_features} training instances that can include ‘covariates’ and with column name as given by outcome_label and censor_label when y=None. ALL INSTANCE ATTRIBUTES MUST BE >0 NUMERIC NOT NAN OR OTHER TYPE
y – None or list of list/tuples with (censoring, duration) {n_samples, 2} labels. ALL INSTANCE OUTCOMES MUST BE NUMERIC NOT NAN OR OTHER TYPE
bin_index – population index of the bin to return group information for
- Returns:
low_outcome, high_outcome, low_censor, and high_censor
- get_bin_population_heatmap_plot(filtering=None, show=True, save=False, output_folder=None, data_name=None)[source]
- get_cox_prop_hazard_adjusted(x, y=None, bin_index=0, use_bin_sums=False, show_progress=False, new_covariates=None)[source]
- get_cox_prop_hazard_unadjust(x, y=None, bin_index=0, use_bin_sums=False, show_progress=False)[source]
- get_custom_bin_population_heatmap_plot(group_names, legend_group_info, colors, max_bins, max_features, show=True, save=False, output_folder=None, data_name=None)[source]
- get_feature_tracking_plot(max_features=50, show=True, save=False, output_folder=None, data_name=None)[source]
- get_kaplan_meir(data, bin_index, show=True, save=False, output_folder=None, data_name=None)[source]
- predict(x, bin_number=None)[source]
Function to predict strata on the basis of top OR bin.
- Parameters:
x – array-like {n_samples, n_features} training instances. ALL INSTANCE ATTRIBUTES MUST BE >0 NUMERIC NOT NAN OR OTHER TYPE, and can include ‘covariates’ OR array-like dataframe {n_samples, n_features} training instances that can include ‘covariates’ and with column name as given by outcome_label and censor_label when y=None. ALL INSTANCE ATTRIBUTES MUST BE >0 NUMERIC NOT NAN OR OTHER TYPE
bin_number – the top nth bin (0 is bin with highest fitness) to consider as the predictor, or if [None] uses a bin-population weighted voting scheme as the predictor
- Returns:
y: prediction of group (0 or 1), e.g. strata group –> low vs. high
- transform(x, y=None, full_sums=False)[source]
Scikit-learn required function for Supervised training of FIBERS
- Parameters:
x – array-like {n_samples, n_features} training instances. ALL INSTANCE ATTRIBUTES MUST BE >0 NUMERIC NOT NAN OR OTHER TYPE, and can include ‘covariates’ OR array-like dataframe {n_samples, n_features} training instances that can include ‘covariates’ and with column name as given by outcome_label and censor_label when y=None. ALL INSTANCE ATTRIBUTES MUST BE >0 NUMERIC NOT NAN OR OTHER TYPE
y – None or list of list/tuples with (censoring, duration) {n_samples, 2} labels. ALL INSTANCE OUTCOMES MUST BE NUMERIC NOT NAN OR OTHER TYPE
- Returns:
Dataset transformed instances into bin-defined features (i.e. value sums of bin-specified features) as a pd.DataFrame