Run predict() on a loaded model
Once the model is loaded, call .predict(X) to get predictions. This is the core of inference benchmarking.
script.py
v3.1
Python output
click Run to execute
Click "Run" to execute the code on the left.
The output will appear here.
The output will appear here.
🧠 How it works
model.predict(X) is the core of inference. X must be 2D: (n_samples, n_features). Even for 1 sample: shape (1, 4), not (4,). Returns a 1D array: (n_samples,) — one prediction per input row. For classification: predict() returns class labels (0, 1, 2...). predict_proba() returns probabilities (n_samples, n_classes). The COMMON BUG at the bottom shows what happens with a 1D array — sklearn either crashes or reshapes it wrong.
✏️ Try these changes
-
Change test_size from 0.2 to 0.5→ bigger test set → more predictions -
Replace LinearRegression with RandomForestRegressor(n_estimators=50)→ different model, same predict() call -
Change new_sample values→ different prediction -
Add predict_proba (need a classifier): use make_classification instead of make_regression→ returns probabilities instead of values