ModelEvaluator
- class ModelEvaluator(*, models=None, list_metrics=None, verbose=True, random_state=None)[source]
ModelEvaluator: rigorous cross-validated evaluation and paired comparison of models (Tool).
Turns a feature matrix
Xandlabelsinto an honest performance table rather than a single optimistic hold-out number.run()scores one or more scikit-learn models by repeated stratified cross-validation (multi-seed mean and std overn_cv * n_roundsfolds) with percentile bootstrap confidence intervals of the mean;eval()compares two or more models pairwise on the same folds with a signeddelta(e.g. ΔMCC) and a two-sided Wilcoxon signed-rank significance test. Both are reproducible underrandom_stateand reusecomp_bootstrap_ci()and scikit-learn metrics — no new dependency.learning_curve()repeats the cross-validation on stratified subsets of increasing size of each training fold, showing whether a task is still sampling-limited (the score keeps rising with more data) or has saturated (a different representation or model is needed).Where
AAPreddeploys a fitted model andTreeModelranks features,ModelEvaluatoranswers “how well does this model generalize, and is model A really better than model B?” with mean±std, confidence intervals, and a paired significance test.Warning
Experimental. This class is part of the evolving prediction layer; its API (signatures, defaults, return objects) may change between minor releases without the usual deprecation cycle. Pin a version if you depend on the current behaviour.
Added in version 1.1.0.
Changed in version 1.2.0: Added
learning_curve()for cross-validated performance across training sizes.Notes
See also
AAPredfor evaluating and deploying prediction models on raw sequences.ModelEvaluatorPlotfor visualizing the evaluation and comparison tables.comp_bootstrap_ci()for the percentile bootstrap confidence interval reused here.
- Parameters:
Methods
eval(*[, metric, ci, random_state])Compare the evaluated models pairwise on a single metric over the shared folds.
learning_curve(X, labels, *[, train_sizes, ...])Evaluate every model at increasing training sizes to show whether a task is sampling-limited.
run(X, labels, *[, n_cv, n_rounds, metrics, ...])Evaluate every model by repeated stratified cross-validation with bootstrap CIs.
- __init__(*, models=None, list_metrics=None, verbose=True, random_state=None)[source]
- Parameters:
models (str, estimator, list, or None, default=None) – Models to evaluate, given as registry name strings (e.g.
"svm","rf"; seeaaanalysis.utils.LIST_PRED_MODELS) and/or configured scikit-learn estimator instances, in any mix. IfNone, evaluates a single"rf"(RandomForestClassifier). Pass two or more to enableeval()(paired comparison). Each model must implementpredict;predict_probais required only for probability metrics (e.g.roc_auc).list_metrics (list of {'accuracy', 'balanced_accuracy', 'precision', 'recall', 'f1', 'roc_auc', 'mcc'} or None, default=None) – Default metrics used by
run()andlearning_curve()when theirmetricsargument isNone. IfNone, uses["accuracy", "balanced_accuracy", "mcc"].verbose (bool, default=True) – If
True, enables progress output; ifFalse, suppresses it.random_state (int or None, default=None) – Seed used for fold shuffling, bootstrap resampling, and supported estimators. If a non-negative integer, these stochastic operations are reproducible; if
None, they are random.aaanalysis.options["random_state"]overrides this value unless it is"off".
Examples
To demonstrate
ModelEvaluator, we obtain theDOM_GSECdataset and its feature matrix:import aaanalysis as aa aa.options["verbose"] = False # Disable verbosity # DOM_GSEC example dataset + a small feature set (see [Breimann25]_) df_seq = aa.load_dataset(name="DOM_GSEC") labels = df_seq["label"].to_list() df_feat = aa.load_features(name="DOM_GSEC").head(20) # Build the CPP feature matrix X sf = aa.SequenceFeature() df_parts = sf.get_df_parts(df_seq=df_seq) X = sf.feature_matrix(features=df_feat["feature"], df_parts=df_parts)
Construct a
ModelEvaluatorwith the models to compare, the defaultlist_metrics,verbose, and arandom_statefor reproducibility:me = aa.ModelEvaluator(models=["rf", "svm"], list_metrics=["accuracy", "balanced_accuracy", "mcc"], verbose=False, random_state=42) df_eval = me.run(X, labels) aa.display_df(df_eval, n_rows=10, show_shape=True)
DataFrame shape: (6, 7)
model metric score score_std ci_low ci_high n_scores 1 rf accuracy 0.809231 0.064659 0.744000 0.843692 5 2 rf balanced_accuracy 0.810256 0.065416 0.744872 0.844231 5 3 rf mcc 0.622289 0.131735 0.491475 0.691125 5 4 svm accuracy 0.848923 0.092943 0.761823 0.920923 5 5 svm balanced_accuracy 0.849359 0.092783 0.761522 0.920513 5 6 svm mcc 0.701250 0.187081 0.523948 0.845931 5