Adapt Automl¶
adapt_automl — mvp.adapt_automl
Cluster: ML & Optimisation | Type: component | MCP Tools: 46
Overview¶
Comprehensive AutoML system with FLAML, AutoGluon, H2O, and sklearn backends. Accepts dict records (from adapt_pandas) or raw float arrays, handles automatic preprocessing (imputation, encoding, scaling), and persists trained models with a 31-tool MCP sub-package covering training, evaluation, model versioning, ensembling, explainability, and an advisory adapter guide.
When to use:
- Automatically selecting and tuning ML models for classification or regression tasks
- Integrating tabular AutoML into an agent pipeline via MCP tools
- Benchmarking multiple backends (FLAML, AutoGluon, H2O) with a unified interface
Example:
from mvp.adapt_automl import AdaptAutoMLBlock, AutoMLInput
block = AdaptAutoMLBlock(name="automl")
result = block.infer(AutoMLInput(
records=[{"age": 25, "income": 50000}, {"age": 40, "income": 80000}],
y=[0, 1],
task="classification",
time_budget_sec=60,
))
# result.ok → True; result.value → AutoMLOutput with best_model, best_score, leaderboard
Works well with: adapt_pandas, adapt_sklearn, align_evals
Validation Notes¶
AutoML scores are strongest when they come from cross-validation or an explicit holdout set. For very small or heavily imbalanced classification datasets, the sklearn fallback may be unable to run reliable cross-validation because one class has too few examples. In that case leaderboard entries are marked with validation: "training_fallback" and ranked by training-set score so the workflow can still complete.
Treat training_fallback scores as a smoke-test signal only. Add more labelled examples or evaluate the saved model with automl_fit_eval, automl_evaluate, or automl_compare_holdout before using the model for production decisions.
Public API¶
PandasToAutoMLAdapter(AIBlock[DataOutput, AutoMLInput, None])¶
Bridge adapt_pandas DataOutput to adapt_automl AutoMLInput.
| Field | Type | Default |
|---|---|---|
name | str | 'pandas_to_automl' |
y_column | str | '' |
task | str | 'auto' |
backend | str | 'auto' |
time_budget_sec | int | 60 |
Methods:
infer(data: DataOutput) -> Result[AutoMLInput]¶
AutoMLGuideRecommendation¶
Validated adapter recommendation decision record.
| Field | Type | Default |
|---|---|---|
adapter | str | required |
reasoning | str | required |
source | str | required |
backend | str | '' |
approach | str | '' |
alternatives | tuple[str, ...] | () |
quick_start | str | '' |
notes | str | '' |
inputs | dict[str, Any] | field(default_factory=dict) |
Methods:
to_dict() -> dict[str, Any]¶
The advisory payload as
adapter_guide.recommend_adapterreturns it.
to_metadata() -> dict[str, Any]¶
AutoMLDecisionError(ValueError)¶
The LLM did not produce a usable, validated adapter recommendation.
LLMAutoMLRuntime¶
Provider-neutral adapter-recommendation runtime over G6's LLM caller.
Constructor:
| Parameter | Type | Default |
|---|---|---|
llm | LLMCaller \| None | None |
Methods:
recommend(inputs: dict[str, Any], floor: 'AutoMLGuideRecommendation', context: str = '') -> Result[dict]¶
AutoMLGuidePlanner¶
Runtime-first facade with the deterministic floor as honest fallback.
Constructor:
| Parameter | Type | Default |
|---|---|---|
runtime | AutoMLRuntime \| None | None |
Methods:
recommend(data_type: str = 'tabular', data_size: str = 'medium', goal: str = 'predict', expertise: str = 'beginner', notes: str = '') -> AutoMLGuideRecommendation¶
AdaptAutoMLBlock(AIBlock[AutoMLInput, AutoMLOutput, None])¶
Comprehensive AutoML block with multi-backend support and preprocessing.
| Field | Type | Default |
|---|---|---|
name | str | 'adapt_automl' |
resource_bounds | ResourceBounds \| None | None |
usage | ResourceUsage | field(default_factory=ResourceUsage) |
Methods:
infer(data: Any) -> Result[AutoMLOutput]¶
PreprocessingConfig(BaseModel)¶
Controls automatic preprocessing. All fields optional with sensible defaults.
| Field | Type | Default |
|---|---|---|
impute_numeric | Literal['median', 'mean', 'zero', 'none'] | 'median' |
impute_categorical | Literal['mode', 'constant', 'none'] | 'mode' |
encode_categorical | Literal['auto', 'label', 'onehot', 'none'] | 'auto' |
scale_numeric | Literal['standard', 'minmax', 'none'] | 'none' |
max_cardinality | int | Field(default=50, ge=1, le=10000) |
feature_engineering | Literal['none', 'polynomial', 'interaction'] | 'none' |
poly_degree | int | Field(default=2, ge=2, le=4) |
datetime_features | bool | False |
variance_threshold | float | Field(default=0.0, ge=0.0) |
feature_selection | Literal['none', 'kbest', 'l1', 'rfe', 'variance'] | 'none' |
select_k | int | Field(default=10, ge=1) |
imbalance_strategy | Literal['none', 'smote', 'adasyn', 'undersample', 'class_weight'] | 'none' |
AutoMLInput(BaseModel)¶
Unified input for AutoML — accepts dict records or float arrays.
| Field | Type | Default |
|---|---|---|
records | list[dict[str, Any]] | Field(default_factory=list) |
X | list[list[float]] | Field(default_factory=list) |
y_column | str | '' |
y | list[float \| int \| str] | Field(default_factory=list) |
feature_columns | list[str] | Field(default_factory=list) |
task | Literal['classification', 'regression', 'auto'] | 'auto' |
backend | Literal['auto', 'flaml', 'autogluon', 'h2o', 'sklearn', 'mljar'] | 'auto' |
time_budget_sec | int | Field(default=60, ge=1, le=_MAX_TIME_BUDGET_SEC) |
n_jobs | int | Field(default=1, ge=1, le=_MAX_N_JOBS) |
metric | str | '' |
preprocessing | PreprocessingConfig | Field(default_factory=PreprocessingConfig) |
LeaderboardEntry(BaseModel)¶
A candidate model on the leaderboard.
| Field | Type | Default |
|---|---|---|
rank | int | required |
name | str | required |
score | float | required |
fit_time_sec | float | 0.0 |
params | dict[str, Any] | Field(default_factory=dict) |
FeatureImportance(BaseModel)¶
Feature importance score.
| Field | Type | Default |
|---|---|---|
feature | str | required |
importance | float | required |
PreprocessingReport(BaseModel)¶
Report of preprocessing steps applied.
| Field | Type | Default |
|---|---|---|
numeric_features | list[str] | Field(default_factory=list) |
categorical_features | list[str] | Field(default_factory=list) |
imputed_columns | list[str] | Field(default_factory=list) |
encoded_columns | list[str] | Field(default_factory=list) |
scaled | bool | False |
n_features_in | int | 0 |
n_features_out | int | 0 |
engineered_features | list[str] | Field(default_factory=list) |
selected_features | list[str] | Field(default_factory=list) |
dropped_low_variance | list[str] | Field(default_factory=list) |
imbalance_applied | str | '' |
warnings | list[str] | Field(default_factory=list) |
AutoMLOutput(BaseModel)¶
Output from the AutoML system.
| Field | Type | Default |
|---|---|---|
best_model | str | required |
best_score | float | required |
n_models_tried | int | required |
task | str | required |
metric | str | required |
backend | str | required |
requested_backend | str | 'auto' |
selected_backend | str | '' |
validation_strength | Literal['none', 'holdout', 'cv', 'cv_holdout'] | 'none' |
leaderboard | list[LeaderboardEntry] | Field(default_factory=list) |
feature_importance | list[FeatureImportance] | Field(default_factory=list) |
preprocessing | PreprocessingReport | Field(default_factory=PreprocessingReport) |
fit_time_sec | float | 0.0 |
interpretation | str | '' |
model_readiness | ModelReadinessRecord \| None | None |
degraded | bool | False |
degradation_reason | str | '' |
degradation | DegradationNotice \| None | None |
warning_card | WarningCard \| None | None |
completion_state | CompletionState | 'qualified-draft' |
evidence | list[dict[str, Any]] | Field(default_factory=list) |
request_id | str | '' |
run_id | str | '' |
readiness | ProblemReadinessReport \| None | None |
governance_card | AutoMLGovernanceCard \| None | None |
artifact_manifest | dict[str, Any] | Field(default_factory=dict) |
structured_report | dict[str, Any] | Field(default_factory=dict) |
AdaptAutoMLMCPBlock(AIBlock[MCPAutoMLInput, MCPAutoMLOutput, dict])¶
MCP AutoML block with persistence and model caching.
| Field | Type | Default |
|---|---|---|
name | str | field(default='adapt_automl_mcp') |
db_path | str | field(default='') |
cache_max_size | int | field(default=32) |
resource_bounds | ResourceBounds \| None | None |
usage | ResourceUsage | field(default_factory=ResourceUsage) |
Methods:
infer(inp: MCPAutoMLInput) -> Result[MCPAutoMLOutput]¶
MCPAutoMLInput(BaseModel)¶
Input for all 31 MCP operations, discriminated by op field.
| Field | Type | Default |
|---|---|---|
op | AutoMLOp | Field(..., description='Operation to perform') |
model_name | str | Field('', description='Named model identifier') |
csv_path | str | '' |
data_type | str | Field('tabular', description='tabular, text, image, timeseries, graph') |
data_size | str | Field('medium', description='tiny, small, medium, large') |
goal | str | Field('predict', description='predict, cluster, optimize, embed, bayesian') |
expertise | str | Field('beginner', description='beginner, intermediate, expert') |
records | list[dict[str, Any]] | Field(default_factory=list) |
X_flat | list[list[float]] | Field(default_factory=list) |
y | list[float \| int \| str] | Field(default_factory=list) |
y_column | str | '' |
feature_columns | list[str] | Field(default_factory=list) |
task | Literal['auto', 'classification', 'regression'] | 'auto' |
backend | Literal['auto', 'sklearn', 'flaml', 'autogluon', 'h2o', 'mljar'] | 'auto' |
time_budget_sec | int | Field(60, ge=1, le=7200) |
n_jobs | int | 1 |
metric | str | '' |
dataset_name | str | '' |
n_samples | int | 0 |
n_features | int | 0 |
notes | str | '' |
export_dir | str | '' |
filter_backend | str | '' |
filter_task | str | '' |
test_size | float | Field(0.2, gt=0.0, lt=1.0) |
stratify | bool | True |
random_seed | int | 42 |
metric_names | list[str] | Field(default_factory=list) |
impute_numeric | str | '' |
impute_categorical | str | '' |
encode_categorical | str | '' |
scale_numeric | str | '' |
max_cardinality | int | 0 |
class_weight | str | '' |
import_path | str | '' |
compare_versions | list[int] | Field(default_factory=list) |
compare_model_names | list[str] | Field(default_factory=list) |
include_models | list[str] | Field(default_factory=list) |
confidence_level | float | Field(0.95, ge=0.5, le=0.99) |
n_bootstrap | int | Field(100, ge=10, le=1000) |
optimize_for | str | Field('f1', description='Metric to optimize: f1, precision, recall, balanced_accuracy') |
top_n | int | Field(3, ge=2, le=10) |
ensemble_method | str | Field('voting', description='voting or stacking') |
explain_type | str | Field('global', description='global or local') |
sample_index | int | Field(0, ge=0) |
warm_start | bool | False |
cv_strategy | str | Field('auto', description='auto, stratified, group, timeseries, repeated') |
group_column | str | '' |
n_repeats | int | Field(3, ge=1, le=10) |
feature_engineering | str | Field('none', description='none, polynomial, interaction') |
poly_degree | int | Field(2, ge=2, le=4) |
feature_selection | str | Field('none', description='none, kbest, l1, rfe, variance') |
select_k | int | Field(10, ge=1) |
variance_threshold | float | Field(0.0, ge=0.0) |
imbalance_strategy | str | Field('none', description='none, smote, adasyn, undersample') |
custom_metric_name | str | '' |
request_id | str | '' |
task_id | str | '' |
run_id | str | '' |
prediction_unit | str | '' |
prediction_time | str | '' |
business_objective | str | '' |
deployment_intent | str | '' |
metric_rationale | str | '' |
native_operation | str | '' |
native_params | dict[str, Any] | Field(default_factory=dict) |
MCPAutoMLOutput(BaseModel)¶
Output from all 31 MCP operations.
| Field | Type | Default |
|---|---|---|
op | str | '' |
success | bool | True |
data | dict[str, Any] | Field(default_factory=dict) |
error | str | '' |
degraded | bool | False |
degradation_reason | str \| None | None |
AutoMLStore¶
SQLite store for AutoML MCP persistence.
Constructor:
| Parameter | Type | Default |
|---|---|---|
db_path | str | _DEFAULT_DB |
Methods:
record_readiness(model_name: str, record: dict[str, Any]) -> None¶
Store the readiness snapshot for
model_name.
get_readiness(model_name: str) -> dict[str, Any] | None¶
schema_version() -> int¶
upsert_model(name: str, backend: str, task: str, metric: str, score: float, n_models_tried: int, model_path: str, preprocessing_json: str, feature_columns_json: str) -> None¶
get_model(name: str, version: int | None = None) -> dict[str, Any] | None¶
list_models() -> list[dict[str, Any]]¶
list_model_versions(name: str) -> list[dict[str, Any]]¶
delete_model(name: str) -> bool¶
save_model_blob(name: str, blob: bytes) -> None¶
get_model_blob(name: str) -> bytes | None¶
add_experiment(model_name: str, backend: str, task: str, metric: str, score: float, n_models_tried: int, notes: str, test_score: float = 0.0, test_size: float = 0.0) -> None¶
list_experiments(backend: str = '', task: str = '') -> list[dict[str, Any]]¶
add_prediction(model_name: str, n_samples: int, backend: str) -> None¶
register_dataset(name: str, n_samples: int, n_features: int, task: str, notes: str) -> None¶
get_dataset(name: str) -> dict[str, Any] | None¶
count_all() -> dict[str, int]¶
Functions¶
agentic_planner_enabled(default_enabled: bool = True) -> bool¶
Decide whether the agentic adapter-planner should be used.
validate_guide_recommendation(rec: Any, allowed: set[str] | frozenset[str] = ALLOWED_ADAPTERS, allowed_backends: set[str] | frozenset[str] = ALLOWED_BACKENDS, allowed_approaches: set[str] | frozenset[str] = ALLOWED_APPROACHES) -> dict¶
Reject any adapter recommendation outside the canonical shape / vocabulary.
guide_floor(data_type: str = 'tabular', data_size: str = 'medium', goal: str = 'predict', expertise: str = 'beginner', notes: str = '') -> AutoMLGuideRecommendation¶
Deterministic decision-tree adapter selector (the honest floor).
MCP Tools¶
| Operation | Source |
|---|---|
fit | automl_mcp |
predict | automl_mcp |
predict_rich | automl_mcp |
predict_proba | automl_mcp |
predict_interval | automl_mcp |
score | automl_mcp |
leaderboard | automl_mcp |
feature_importance | automl_mcp |
model_list | automl_mcp |
model_delete | automl_mcp |
model_info | automl_mcp |
experiment_list | automl_mcp |
dataset_register | automl_mcp |
get_info | automl_mcp |
export_model | automl_mcp |
fit_eval | automl_mcp |
evaluate | automl_mcp |
import_model | automl_mcp |
data_profile | automl_mcp |
confusion_matrix | automl_mcp |
compare_versions | automl_mcp |
model_versions | automl_mcp |
cv_details | automl_mcp |
threshold_tune | automl_mcp |
partial_fit | automl_mcp |
ensemble | automl_mcp |
compare_holdout | automl_mcp |
explain | automl_mcp |
train_from_csv | automl_mcp |
guide | automl_mcp |
list_patterns | automl_mcp |
discover_capabilities | automl_mcp |
dependency_health | automl_mcp |
backend_matrix | automl_mcp |
backend_native_op | automl_mcp |
structured_report | automl_mcp |
artifact_manifest | automl_mcp |
auto | automl_mcp |
classification | automl_mcp |
regression | automl_mcp |
auto | automl_mcp |
sklearn | automl_mcp |
flaml | automl_mcp |
autogluon | automl_mcp |
h2o | automl_mcp |
mljar | automl_mcp |