SynaptIX logoSynaptIX

Model Selection

v0.1.7

Cross-validation, hyperparameter tuning and model comparison: k-fold cross_validate, GridSearch with best params, and compare_models — an AutoML-lite sweep over 7 classifiers or 7 regressors.

Compare Models

compare.py
import synaptix as sx

df = sx.load_dataset("iris")
X, y = df.drop(columns="species"), df["species"]

# Cross-validated comparison of 7 classifiers
tabla = sx.model_selection.compare_models(X, y, task="classification", cv=5)
print(tabla)   # DataFrame sorted by score: score, std, fit time

# The table exports to a ViewX dashboard (synaptix[viewx])
tabla.to_dashboard("comparacion.html")

Cross-Validation & Tuning

tune.py
import synaptix as sx

model = sx.supervised.RandomForestClassifier(random_state=42)

# k-fold cross-validation
cv = sx.model_selection.cross_validate(model, X, y, cv=10)
print("Score: %.3f ± %.3f" % (cv.mean_score, cv.std_score))

# GridSearch: retrained best model
search = sx.model_selection.GridSearch(
    model,
    {"n_estimators": [50, 100, 200], "max_depth": [None, 5, 10]},
    cv=5,
)
search.fit(X, y)
best = search.best_estimator_
print("Best score:", search.best_score_)
print("Best params:", search.best_params_)

API Reference

cross_validate
cross_validate(model, X, y, cv=5) -> CrossValidationResult
GridSearch
GridSearch(model, param_grid, cv=5)
compare_models
compare_models(X, y, task='classification', cv=5) -> ModelComparisonResult

Default Grids

synaptix.pipeline.grids.DEFAULT_GRIDS ships sensible grids per model — AutoPipeline uses them for its tuning step, and you can reuse them in your own GridSearch calls.