Full benchmark engine — putting it all together
The complete benchmarking function: load .pkl → detect model type → load dataset → predict → time → metrics → return JSON. This is what OpenBenchML does.
The output will appear here.
This is the COMPLETE benchmark engine — exactly what OpenBenchML does. 8 steps: load → validate → split → time → detect type → metrics → CV → importances. KEY INSIGHT: the function takes model BYTES (not a file path) — that's what you get from UploadFile.read(). Duck typing throughout: hasattr(model, 'predict'), hasattr(model, 'feature_importances_'). Works with LinearRegression, RandomForest, XGBoost, LightGBM, ANY model with .predict(). Auto-detects regression vs classification by checking y_pred.dtype. Returns a dict that FastAPI can serialize to JSON directly. The 2 tests at the bottom prove it works with BOTH regression AND classification models — same function, no changes.
-
Change CV folds from 5 to 10→ more folds, slower, slightly more accurate -
Add a 'training_time' field by re-fitting the model + timing it→ measures how long training takes -
Replace LogisticRegression with RandomForestClassifier→ same function works — that's the point -
Add error handling for when X has wrong number of features→ model.predict crashes if features don't match