Package: autoprognosis
AutoPrognosis - A system for automating the design of predictive modeling pipelines tailored for clinical prognosis.:key: Features:rocket: Automatically learns ensembles of pipelines for classification, regression or survival analysis tasks.:cyclone: Easy to extend pluginable architecture.:fire: Interpretability and uncertainty quantification tools.:adhesive_bandage: Data imputation usingHyperImpute.:zap: Build demonstrators usingStreamlit.:notebook:PythonandR tutorialsavailable.:book:Read the docs:rocket: InstallationUsing pipThe library can be installed from PyPI using$pipinstallautoprognosisor from source, using$pipinstall.Redis (Optional, but recommended)AutoPrognosis can use Redis as a backend to improve the performance and quality of the searches.For that, install the redis-server package following the steps described on theofficial site.Environment variablesThe library can be configured from a set of environment variables.VariableDescriptionN_OPT_JOBSNumber of cores to use for hyperparameter search. Default : 1N_LEARNER_JOBSNumber of cores to use by inidividual learners. Default: all cpusREDIS_HOSTIP address for the Redis database. Default 127.0.0.1REDIS_PORTRedis port. Default: 6379Example:export N_OPT_JOBS = 2to use 2 cores for hyperparam search.:boom: Sample UsageAdvanced Python tutorialscan be found in thePython tutorials section.R examplescan be found in theR tutorials section.List the available classifiersfromautoprognosis.plugins.prediction.classifiersimportClassifiersprint(Classifiers().list_available())Create a study for classifiersfromsklearn.datasetsimportload_breast_cancerfromautoprognosis.studies.classifiersimportClassifierStudyfromautoprognosis.utils.serializationimportload_model_from_filefromautoprognosis.utils.testerimportevaluate_estimatorX,Y=load_breast_cancer(return_X_y=True,as_frame=True)df=X.copy()df["target"]=Ystudy_name="example"study=ClassifierStudy(study_name=study_name,dataset=df,# pandas DataFrametarget="target",# the label column in the dataset)model=study.fit()# Predict the probabilities of each class using the modelmodel.predict_proba(X)(Advanced)Customize the study for classifiersfrompathlibimportPathfromsklearn.datasetsimportload_breast_cancerfromautoprognosis.studies.classifiersimportClassifierStudyfromautoprognosis.utils.serializationimportload_model_from_filefromautoprognosis.utils.testerimportevaluate_estimatorX,Y=load_breast_cancer(return_X_y=True,as_frame=True)df=X.copy()df["target"]=Yworkspace=Path("workspace")study_name="example"study=ClassifierStudy(study_name=study_name,dataset=df,# pandas DataFrametarget="target",# the label column in the datasetnum_iter=100,# how many trials to do for each candidatetimeout=60,# secondsclassifiers=["logistic_regression","lda","qda"],workspace=workspace,)study.run()output=workspace/study_name/"model.p"model=load_model_from_file(output)# <model> contains the optimal architecture, but the model is not trained yet. You need to call fit() to use it.# This way, we can further benchmark the selected model on the training set.metrics=evaluate_estimator(model,X,Y)print(f"model{model.name()}->{metrics['str']}")# Train the modelmodel.fit(X,Y)# Predict the probabilities of each class using the modelmodel.predict_proba(X)List the available regressorsfromautoprognosis.plugins.prediction.regressionimportRegressionprint(Regression().list_available())Create a Regression study# third partyimportpandasaspd# autoprognosis absolutefromautoprognosis.utils.serializationimportload_model_from_filefromautoprognosis.utils.testerimportevaluate_regressionfromautoprognosis.studies.regressionimportRegressionStudy# Load datasetdf=pd.read_csv("https://archive.ics.uci.edu/ml/machine-learning-databases/00291/airfoil_self_noise.dat",header=None,sep="\\t",)last_col=df.columns[-1]y=df[last_col]X=df.drop(columns=[last_col])df=X.copy()df["target"]=y# Search the modelstudy_name="regression_example"study=RegressionStudy(study_name=study_name,dataset=df,# pandas DataFrametarget="target",# the label column in the dataset)model=study.fit()# Predict using the modelmodel.predict(X)AdvancedCustomize the Regression study# stdlibfrompathlibimportPath# third partyimportpandasaspd# autoprognosis absolutefromautoprognosis.utils.serializationimportload_model_from_filefromautoprognosis.utils.testerimportevaluate_regressionfromautoprognosis.studies.regressionimportRegressionStudy# Load datasetdf=pd.read_csv("https://archive.ics.uci.edu/ml/machine-learning-databases/00291/airfoil_self_noise.dat",header=None,sep="\\t",)last_col=df.columns[-1]y=df[last_col]X=df.drop(columns=[last_col])df=X.copy()df["target"]=y# Search the modelworkspace=Path("workspace")workspace.mkdir(parents=True,exist_ok=True)study_name="regression_example"study=RegressionStudy(study_name=study_name,dataset=df,# pandas DataFrametarget="target",# the label column in the datasetnum_iter=10,# how many trials to do for each candidate. Default: 50num_study_iter=2,# how many outer iterations to do. Default: 5timeout=50,# timeout for optimization for each classfier. Default: 600 secondsregressors=["linear_regression","xgboost_regressor"],workspace=workspace,)study.run()# Test the modeloutput=workspace/study_name/"model.p"model=load_model_from_file(output)# <model> contains the optimal architecture, but the model is not trained yet. You need to call fit() to use it.# This way, we can further benchmark the selected model on the training set.metrics=evaluate_regression(model,X,y)print(f"Model{model.name()}score:{metrics['str']}")# Train the modelmodel.fit(X,y)# Predict using the modelmodel.predict(X)List available survival analysis estimatorsfromautoprognosis.plugins.prediction.risk_estimationimportRiskEstimationprint(RiskEstimation().list_available())Create a Survival analysis study# third partyimportnumpyasnpfrompycoximportdatasets# autoprognosis absolutefromautoprognosis.studies.risk_estimationimportRiskEstimationStudyfromautoprognosis.utils.serializationimportload_model_from_filefromautoprognosis.utils.testerimportevaluate_survival_estimatordf=datasets.gbsg.read_df()df=df[df["duration"]>0]X=df.drop(columns=["duration"])T=df["duration"]Y=df["event"]eval_time_horizons=np.linspace(T.min(),T.max(),5)[1:-1]study_name="example_risks"study=RiskEstimationStudy(study_name=study_name,dataset=df,target="event",time_to_event="duration",time_horizons=eval_time_horizons,)model=study.fit()# Predict using the modelmodel.predict(X,eval_time_horizons)AdvancedCustomize the Survival analysis study# stdlibimportosfrompathlibimportPath# third partyimportnumpyasnpfrompycoximportdatasets# autoprognosis absolutefromautoprognosis.studies.risk_estimationimportRiskEstimationStudyfromautoprognosis.utils.serializationimportload_model_from_filefromautoprognosis.utils.testerimportevaluate_survival_estimatordf=datasets.gbsg.read_df()df=df[df["duration"]>0]X=df.drop(columns=["duration"])T=df["duration"]Y=df["event"]eval_time_horizons=np.linspace(T.min(),T.max(),5)[1:-1]workspace=Path("workspace")study_name="example_risks"study=RiskEstimationStudy(study_name=study_name,dataset=df,target="event",time_to_event="duration",time_horizons=eval_time_horizons,num_iter=10,num_study_iter=1,timeout=10,risk_estimators=["cox_ph","survival_xgboost"],score_threshold=0.5,workspace=workspace,)study.run()output=workspace/study_name/"model.p"model=load_model_from_file(output)# <model> contains the optimal architecture, but the model is not trained yet. You need to call fit() to use it.# This way, we can further benchmark the selected model on the training set.metrics=evaluate_survival_estimator(model,X,T,Y,eval_time_horizons)print(f"Model{model.name()}score:{metrics['str']}")# Train the modelmodel.fit(X,T,Y)# Predict using the modelmodel.predict(X,eval_time_horizons):high_brightness: TutorialsPluginsImputationPreprocessingClassificationPipelinesInterpretabilitySurvival AnalysisRegressionAutoMLClassification tasksClassification tasks with imputationSurvival analysis tasksSurvival analysis tasks with imputationRegression tasksClassifiers with explainersMultiple imputation exampleBuilding a demonstratorClassification demonstratorSurvival analysis demonstrator:zap: PluginsImputation methodsfromautoprognosis.plugins.imputersimportImputersimputer=Imputers().get(<NAME>)NameDescriptionhyperimputeIterative imputer using both regression and classification methods based on linear models, trees, XGBoost, CatBoost and neural netsmeanReplace the missing values using the mean along each column withSimpleImputermedianReplace the missing values using the median along each column withSimpleImputermost_frequentReplace the missing values using the most frequent value along each column withSimpleImputermissforestIterative imputation method based on Random Forests usingIterativeImputerandExtraTreesRegressoriceIterative imputation method based on regularized linear regression usingIterativeImputerandBayesianRidgemiceMultiple imputations based on ICE usingIterativeImputerandBayesianRidgesoftimputeLow-rank matrix approximation via nuclear-norm regularizationEMIterative procedure which uses other variables to impute a value (Expectation), then checks whether that is the value most likely (Maximization) -EM imputation algorithmgainGAIN: Missing Data Imputation using Generative Adversarial NetsPreprocessing methodsfromautoprognosis.plugins.preprocessorsimportPreprocessorspreprocessor=Preprocessors().get(<NAME>)NameDescriptionmaxabs_scalerScale each feature by its maximum absolute value.MaxAbsScalerscalerStandardize features by removing the mean and scaling to unit variance. -StandardScalerfeature_normalizerNormalize samples individually to unit norm.Normalizernormal_transformTransform features using quantiles information.QuantileTransformeruniform_transformTransform features using quantiles information.QuantileTransformerminmax_scalerTransform features by scaling each feature to a given range.MinMaxScalerClassificationfromautoprognosis.plugins.prediction.classifiersimportClassifiersclassifier=Classifiers().get(<NAME>)NameDescriptionneural_netsPyTorch based neural net classifier.logistic_regressionLogisticRegressioncatboostGradient boosting on decision trees -CatBoostrandom_forestA random forest classifier.RandomForestClassifiertabnetTabNet : Attentive Interpretable Tabular LearningxgboostXGBoostClassifierSurvival Analysisfromautoprognosis.plugins.prediction.risk_estimationimportRiskEstimationpredictor=RiskEstimation().get(<NAME>)NameDescriptionsurvival_xgboostXGBoost Survival Embeddingsloglogistic_aftLog-Logistic AFT modeldeephitDeepHit: A Deep Learning Approach to Survival Analysis with Competing Riskscox_phCox’s proportional hazard modelweibull_aftWeibull AFT model.lognormal_aftLog-Normal AFT modelcoxnetCoxNet is a Cox proportional hazards model also referred to as DeepSurvRegressionfromautoprognosis.plugins.prediction.regressionimportRegressionregressor=Regression().get(<NAME>)NameDescriptiontabnet_regressorTabNet : Attentive Interpretable Tabular Learningcatboost_regressorGradient boosting on decision trees -CatBoostrandom_forest_regressorRandomForestRegressorxgboost_regressorXGBoostClassifierneural_nets_regressionPyTorch-based neural net regressor.linear_regressionLinearRegressionExplainersfromautoprognosis.plugins.explainersimportExplainersexplainer=Explainers().get(<NAME>)NameDescriptionrisk_effect_sizeFeature importance using Cohen's distance between probabilitieslimeLime: Explaining the predictions of any machine learning classifiersymbolic_pursuit[Symbolic Pursuit](Learning outside the black-box: at the pursuit of interpretable models)shap_permutation_samplerSHAP Permutation Samplerkernel_shapSHAP KernelExplainerinvaseINVASE: Instance-wise Variable SelectionUncertaintyfromautoprognosis.plugins.uncertaintyimportUncertaintyQuantificationmodel=UncertaintyQuantification().get(<NAME>)NameDescriptioncohort_explainerconformal_predictionjackknife:hammer: TestAfter installing the library, the tests can be executed usingpytest$pipinstall.[testing]$pytest-vxs-m"not slow"CitingIf you use this code, please cite the associated paper:@misc{https://doi.org/10.48550/arxiv.2210.12090,
  doi = {10.48550/ARXIV.2210.12090},
  url = {https://arxiv.org/abs/2210.12090},
  author = {Imrie, Fergus and Cebere, Bogdan and McKinney, Eoin F. and van der Schaar, Mihaela},
  keywords = {Machine Learning (cs.LG), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
  title = {AutoPrognosis 2.0: Democratizing Diagnostic and Prognostic Modeling in Healthcare with Automated Machine Learning},
  publisher = {arXiv},
  year = {2022},
  copyright = {Creative Commons Attribution 4.0 International}
}ReferencesAutoPrognosis: Automated Clinical Prognostic Modeling via Bayesian Optimization with Structured Kernel LearningPrognostication and Risk Factors for Cystic Fibrosis via Automated Machine LearningCardiovascular Disease Risk Prediction using Automated Machine Learning: A Prospective Study of 423,604 UK Biobank Participants