Package: exhaufs
ExhauFSExhaustive feature selection for classification and survival analysis. Please cite this paper if you are using ExhauFS in your work:Nersisyan S, Novosad V, Galatenko A, Sokolov A, Bokov G, Konovalov A, Alekseev D, Tonevitsky A. ExhauFS: exhaustive search-based feature selection for classification and survival regression. bioRxiv. 2021 Aug 04. doi:10.1101/2021.08.03.454798.Table of ContentsIntroductionInstallationTutorialRunning ExhauFSFunctions and classesIntroductionThe main idea behind ExhauFS is the exhaustive search of feature subsets to construct the most powerful classification and survival regression models. Since computational complexity of such approach grows exponentially with respect to combination length, we first narrow down features list in order to make the search practically feasible. Briefly, a pipeline is implemented as follows:Feature pre-selection:filter features by specified method.Feature selection:select "best"nfeatures for exhaustive search.Exhaustive search:iterate through all possiblek-element feature subsets and fit classification/regression models.Evaluation:evaluate each model and make summary of all passed feature subsetsValuesnandkalso define running time of the pipeline (there areCnkfeature subsets). And, for example, iterating through all 8-gene signatures composed ofn = 20genes is possible (see example breast cancer data below), while search overn = 1000genes is impossible due to time constraints.Input data can consist from different batches (datasets), and each dataset should be labeled by one of the following types:Training set:samples from training datasets will be used for tuning classification/regression models. At least one such dataset is required; if multiple given, the union will be used.Filtration set:all tuned models will be first evaluated on training and filtration sets. If specified thresholds for accuracy are reached, model will be evaluated on validation (test) sets. The use of filtration sets is optional.Validation (test) set:performance of models that passed filtration thresholds then evaluated on validation sets. At least one such dataset is required; if multiple given, model will be evaluated on all test sets independently.InstallationPrerequisites:Make sure you have installed all of the following prerequisites on your development machine:python3.6+pip3ExhauFS installation:pip3 install exhaufsTutorialIn this section we illustrate the main functionality of ExhauFS, and
together with that show how to reproduce the results present in
the manuscript.A toy example (classification)We illustrate ExhauFS basics by using a smallcervical cancer toy datasetwith 72 samples and 19 features. All necessary data for this example can be found intutorial/cervical_cancerdirectory.We start fromdata.csvandannotation.csvfiles: the first one contains data matrix and the
second one maps each sample to class label and dataset type (training or validation). In this
example we brute force all existing feature triples - this information is reflected inn_k.csvfile (n = 19 is the total number of features). Prior to ExhauFS run we should also create
a configuration file. Here we use random forest classifier and standard accuracy metrics
(config_for_build_classifiers.json). Since all 19 features are used, we do not specify any
feature selector and pre-selector. In order to get only highly accurate classifiers, we impose
0.9 threshold on the minimum of sensitivity (TPR) and specificity (TNR) on the training set.Now we are ready to execute ExhauFS:exhaufs build classifiers -c config_for_build_classifiers.jsonOutput files are located inresults_build_classifiersdirectory.
In this example, we focus only on two reports:models.csvThis file contains accuracy metrics for all models which passed 0.9 threshold filtration on the training set.
The file is sorted according to the classifier accuracy on the training set, so
we can see that almost all models have sensitivity and specificity equal to 1.0.
Among these models there are multiple cases with particularly high accuracy on the validation set, e.g.summary_features.csvHere we see a number of occurrences of each feature in the set of
constructed models which passed 0.9 accuracy threshold. The most
important features could be picked, e.g., by taking rows with FDR < 0.05.Let us take a closer look to the particular classifier built on
perception_vulnerability, socialSupport_instrumental and empowerment_desires features.
To do that, we should create an
additional configuration file withfeatures_subsetparameter set to the desired
triple (config_for_summary_classifiers.json). To run ExhauFS in the summary mode,
simply execute the following command:exhaufs summary classifiers -c config_for_summary_classifiers.jsonNote, that we do not specify any feature selection/pre-selection or
accuracy threshold parameters for the summary mode. The most important of
generated files are:report.txt: accuracy scores for the training and the validation datasets.ROC_CervicalCancerBehaviorRisk_Training.pdf: ROC curve for the training set.
The red dot stands for actual sensitivity and specificity. For example, the classifier
does not work ideally on the training set despite AUC equals 1.ROC_CervicalCancerBehaviorRisk_Validation.pdf: ROC curve for validation set.Breast cancer (classification)As a real-life example of the classification module of the tool we used multi-cohort breast cancer dataset.
The objective is to predict whether a patient will have cancer recurrence within first 5 years after the surgery
based on gene expression profile in the removed tumor (see our manuscript for the details).
Configuration and output files for this example are
located intutorial/breast_cancerfolder, input data can be downloadedhere. The microarray data are split into independent training, filtration and validation sets.The following options are used (config_for_build_classifiers.json):"feature_pre_selector": "f_test"- this is for pre-selection of genes whose expression distribution is similar in training and filtration datasets (the batch effect removal approach)."feature_selector": "t_test"- top n most differentially expressed genes are selected. Additional option"use_filtration": truemeans that Student's t-test will be applied to the union of training and filtration sets."preprocessor": "StandardScaler"- prior classifier fitting, data are centered and scaled (z-score transformation)."model": "SVC"- Support Vector machine Classifier (SVC) is used. Additional arguments are used to specify linear kernel, normalization for unbalanced classes and a cross-validation grid for penalty parameter (C) estimation.Classifier construction with the givenn_k.csvfile could be done by the same command
as in the previous toy example (however, this will take several days to finish).
Here we review two output reports which were not covered in the toy example:summary_n_k.csvFor eachn, kpair the number of classifiers which passed the 0.65 accuracy threshold
on the training and the filtration sets is presented (num_training_reliable). All
these classifiers were evaluated on the validation set; num_validation_reliable and
percentage_reliable columns contain the fraction of these classifiers which also
passed 0.65 accuracy threshold on the validation set. For all values of k above
10 we see almost 100% passability, which means the absence of overfitting and successful
victory over the batch effects (all classifiers which demonstrated reliable performance
on the training and the filtration sets were also good on the validation one).sorted_features.txtThis is a technical though useful file: the list of pre-selected genes is sorted according to the rate of
differential expression (t_testfeature selection). Each pipeline iteration begins from
the selection of the firstnentries from this file.As in the previous toy example, let us take a closer look to the single gene signature
(seeconfig_for_summary_classifiers.json). The following output files were not
covered in the toy example:feature_importances.pdf(contains coefficients of the linear SVM classifier)model.pkl(Python-pickled classifier and pre-processor objects)ExhauFS also allows one to evaluate constucted classifiers on time-to-event data.
For example, let us evaluate the same ten-gene signature on
additional RNA-seq TCGA-BRCA dataset. To do that, we should include to desired feature
subset and pickled model path to the configuration file (config_for_km_plot.json).
The analysis could be done by runningexhaufs km_plot -c config_for_km_plot.jsonThis will generate the Kaplan-Meier plot (results_km_plot/KM_TCGA-BRCA_Validation.pdf).Colorectal cancer (survival regression)As a real-life example of the regression part of the tool we used colorectal cancer dataset.Transformed data and config used for pipeline can be foundhere.Same with classification, the main objective was to analyse contribution of different feature [pre]selection techniques and accuracy scores using Cox Regression as a main model.We achieved best results usingconcordance_indexas a feature selector and as a main scoring function.Again, same with classification, firstly we need to maken, kgrid table for the pipeline.As a result ofexhaufs estimate regressors -c confifg_for_estimate_regressors.json --max_estimated_time 3 --max_k 20we got theestimated_times.csvtable withn/kgrid and predicted running time for each pair of values.Same with examples above, we can build regression models or make summary for one specific set of features as follows:exhaufs build regressors -c confifg_for_build_regressors.jsonwill produce same files as for classification task.exhaufs summary regressors -c confifg_for_summary_regressors.jsonwill produce a detailed report for the specified set of features and also a Kaplan-Meier plots for each dataset type.Whereconfifg_for_build_regressors.jsonandconfifg_for_summary_regressors.jsoncan be found in thetutorial/colorectal_cancerdirectory.Running ExhauFSStep 1: data preparationBefore running the tool, you should prepare three csv tables containing actual data, its annotation andn/kgrid. Both for classification and survival analysis data table should contain numerical values associated with samples (rows) and features (columns):ExampleFeature 1Feature 2Sample 117.17365.1Sample 256.99123.9...Sample 9822.22123.4Sample 9923.23567.8...Sample 51110.82665.8Sample 51211.11200.2Annotation table format is different for classification and survival analysis. For classification it should contain binary indicator of sample class (e.g., 1 for recurrent tumor and 0 for non-recurrent), dataset (batch) label and dataset type (Training/Filtration/Validation).It is important thatClass = 1represents "Positives" andClass = 0are "negatives", otherwise accuracy scores may be calculated incorrectly.Note that annotation should be present for each sample listed in the data table in the same order:ExampleClassDatasetDataset typeSample 11GSE3494TrainingSample 20GSE3494Training...Sample 980GSE12093FiltrationSample 990GSE12093Filtration...Sample 5111GSE1456ValidationSample 5121GSE1456ValidationFor survival analysis, annotation table should contain binary event indicator and time to event:ExampleEventTime to eventDatasetDataset typeSample 11100.1GSE3494TrainingSample 20500.2GSE3494Training...Sample 980623.9GSE12093FiltrationSample 990717.1GSE12093Filtration...Sample 511140.5GSE1456ValidationSample 512166.7GSE1456ValidationTable withn/kgrid for exhaustive feature selection:nis a number of selected features,kis a length of each features subset.If you are not sure what values fornkto use, seeStep 3: defining an,kgridExamplenk10011002......20520102015Step 2: creating configuration fileConfiguration file is a json file containing all customizable parameters for the model (classification and survival analysis)Available parameters🔴!NOTE! - All paths to files / directories can be either relative to the configuration file directory or absolute pathsdata_pathPath to csv table of the data.annotation_pathPath to csv table of the data annotation.n_k_pathPath to an/kgrid file.output_dirPath to directory for output files. If it doesn't exist, it will be created.feature_pre_selectorName of feature pre-selection function fromfeature pre-selectors section.feature_pre_selector_kwargsObject/Dictionary of keyword arguments for feature pre-selector function.feature_selectorName of feature selection function fromfeature selectors section.feature_selector_kwargsObject/Dictionary of keyword arguments for feature selector function. Booleanuse_filtrationindicates whether to useFiltrationdataset besidesTrainingdataset for the selector function.preprocessorName of class for data preprocessing fromsklearn.preprocessing.preprocessor_kwargsObject/Dictionary of keyword arguments for preprocessor class initialization.If you are usingsklearnmodel, usekwargsparameters from the documentation of the model.modelName of class for classification / survival analysis fromClassifiers / Regressors section.model_kwargsObject/Dictionary of keyword arguments for model initialization.If you are usingsklearnmodel, usekwargsparameters from the documentation of the model.model_CV_rangesObject/Dictionary defining model parameters which should be cross-validated. Keys are parameter names, values are lists for grid search.model_CV_foldsNumber of folds for K-Folds cross-validation.scoring_functionsList with names for scoring functions (fromAccuracy scores section) which will be calculated for each model. If you need to pass parameters to the function (e.g.yearin dynamic auc score), you can use object {"name":function name, "kwargs":parameters object}.main_scoring_functionKey from scoring_functions dict defining the "main" scoring function which will be optimized during cross-validation and will be used for model filtering.main_scoring_thresholdA number defining threshold for model filtering: models with score below this threshold on training/filtration sets will not be further evaluated.n_processesNumber of processes / threads to run on.random_stateRandom seed (set to an arbitrary integer for reproducibility).verboseIftrue, print running time for each pair ofn,k.Step 3: defining an,kgridTo estimate running time of the exhaustive pipeline and define adequaten/kvalues you can run:exhaufsestimateregressors|classifiers-c<config_file>--max_k<max_k>--max_estimated_time<max_estimated_time>whereconfig_fileis the path to json configuration file.max_kis the maximum length of each features subset.max_estimated_timeis the time constraint (in hours) for a pipeline running time on one pair of (n, k).Above script calculates maximum possible valuesn/kfor eachk=1...max_ksuch that pipeline running time for each pair (n,k) is less thenmax_estimated_timeStep 4: running the exhaustive pipelineWhen input data, configuration file andn/kgrid are ready,the exhaustive pipeline can be executed as follows -Classifiers:exhaufsbuildclassifiers-c<config_file>Regressors:exhaufsbuildregressors-c<config_file>This will generate multiple files in the specified output folder:models.csv: this file contains all models (classifiers or regressors) which passed the filtration together with their quality metrics.summary_n_k.csv: for each pair ofn,kthree numbers are given: number of models which passed the filtration,
number of models which showed reliable performance (i.e., passed quality thresholds) on the validation set and
their ratio (in %). Low percentage of validation-reliable models together with high number of
filtration-reliable models is usually associated with overfitting.summary_features.csv: for each pair (n, k), for each feature, percentage of models carrying this feature
is listed (only models which passed the filtration are considered).Step 5: generating report for a single modelTo get detailed report on the specific model (== specific set of features):Create configuration file (use ./examples/make_(classifier | regressor)_summary/config.json as a template) and set following key parameters:data_path- path to dataset used for search of classifiers or regressorsannotation_path- path to annotation fileoutput_dir- path to output directory for detailed reportfeatures_subset- set of features belonging to the classifier or regressor of interest;saving_format- either "tiff" or "pdf": format of the saved plots documents;For classifier runexhaufs summary classifiers -c <config_file>For regressor runexhaufs summary regressors -c <config_file>Check the detailed report in theoutput_dirIf you also have time-to-event data for classification problem, you can make Kaplan-Meier plots based on the classifier predictions.To do so you can runexhaufs km_plot -c <config_file>and check theoutput_dirdirectory.You can also specifyKM_x_labelandKM_y_labelin the config to change plot axis names.Functions and classesFeature pre-selectorsfrom_filePre-select features from a given filename: from_filekwargs:{"sep":" "}f_testPre-select features without difference between different datasets and typesname: f_testFeature selectorsfrom_fileSelect first n features from a given filename: from_filekwargs:{"sep":" "}t_testSelect n features with the lowest p-values according to t-testname: t_testkwargs:{"use_filtration":false// whether to use filtration dataset with training dataset}spearman_correlationSelect n features with the highest correlation with target labelname: spearman_correlationkwargs:{"use_filtration":false// whether to use filtration dataset with training dataset}medianSelect n features with the highest median valuename: mediankwargs:{"use_filtration":false// whether to use filtration dataset with training dataset}Classification specific selectors:l1_logistic_regressionSelect n features with the highest concordance index on one-factor Cox regression.name: l1_logistic_regressionkwargs:{"C_low":0,// minumum inverse l1 penalizer value"C_high":1000000,// maximum inverse l1 penalizer value"max_iter":1000,// maximum number of iteration until non-convergance error"use_filtration":false// whether to use filtration dataset with training dataset}Regression specific selectors:cox_concordanceSelect n features with the highest concordance index on one-factor Cox regression.name: cox_concordancekwargs:{"use_filtration":false// whether to use filtration dataset with training dataset}cox_dynamic_aucSelect n features with the highest time-dependent auc on one-factor Cox regression.name: cox_dynamic_auckwargs:{"year":3,// time at which to calculate auc"use_filtration":false// whether to use filtration dataset with training dataset}cox_hazard_ratioSelect n features with the highest hazard ratio on one-factor Cox regression.name: cox_hazard_ratiokwargs:{"use_filtration":false// whether to use filtration dataset with training dataset}cox_likelihoodSelect n features with the highest log-likelihood on one-factor Cox regression.name: cox_likelihoodkwargs:{"use_filtration":false// whether to use filtration dataset with training dataset}l1_coxSelect n features with sparse L1-penalized Cox model.name: l1_coxkwargs:{"p_low":0,// minumum l1 penalizer value"p_high":1000000,// maximum l1 penalizer value"max_iter":1000,// maximum number of iteration until non-convergance error"use_filtration":false// whether to use filtration dataset with training dataset}ClassifiersSVCKNeighborsClassifierRandomForestClassifierXGBClassifierAs amodel_kwargsvalue - use parameters from the documentation of chosen model.Accuracy scoresTPRFPRTNRmin_TPR_TNRRegressorsCoxRegressionAccuracy scoresconcordance_indexdynamic_auchazard_ratiologrank