Train your first model
MLJAR AutoML trains and compares models for your table of data. This example predicts median house values using California Housing data, then opens a report showing the results. It runs on a CPU; no GPU or optional model packages are needed.
1. Install
In a Python 3.11 or newer virtual environment, run:
python -m pip install "mljar-supervised==1.4.0"
Need help setting up Python? See the installation guide.
2. Train and predict
Save the code below as getting_started_housing.py, or
download the script.
Run it in a new working directory:
python getting_started_housing.py
The dataset downloads on first use. We use 5,000 rows to keep the example small:
4,000 for training and model selection, and 1,000 set aside for the final test.
X contains the input columns; y is the value we want to predict.
from sklearn.datasets import fetch_california_housing
from sklearn.metrics import root_mean_squared_error
from sklearn.model_selection import train_test_split
from supervised import AutoML
X, y = fetch_california_housing(return_X_y=True, as_frame=True)
X, _, y, _ = train_test_split(X, y, train_size=5000, random_state=42)
y = y * 100_000 # Convert the target to US dollars.
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, random_state=42
)
automl = AutoML(
results_path="AutoML_Housing",
mode="Explain",
algorithms=["Baseline", "Decision Tree", "Linear", "LightGBM"],
total_time_limit=120,
n_jobs=2,
)
automl.fit(X_train, y_train)
predictions = automl.predict(X_test)
rmse = root_mean_squared_error(y_test, predictions)
print(f"Test RMSE: ${rmse:,.0f}")
automl.report() # Open AutoML_Housing/README.html in your browser.
Explain mode is a useful starting point. Here we request four CPU model types,
two CPU threads, and a 120-second training budget. Training can finish earlier;
data downloads and report generation add to the total runtime.
RMSE measures prediction error in dollars; lower is better. The printed test score uses the 1,000 rows excluded from training and model selection.
In our recorded run, training finished in 15.8 seconds and selected 4_Default_LightGBM.
Test RMSE: $50,963
Your timings and scores can vary with hardware and dependency versions.
3. Open the report
Open AutoML_Housing/README.html in your browser. The top cards show the
selected model, its validation score, and the number of models in the report.
Click any model row to inspect its settings and plots.
Explore this example report How to read reports
The leaderboard uses validation scores to compare models. The printed test score measures the chosen model on separate rows, so the two scores will usually differ.
4. Use the saved model
AutoML saves its models during training. In the same Python session, reload the saved run and predict three rows:
saved = AutoML(results_path="AutoML_Housing")
print(saved.predict(X_test.head(3)))
In a new session, import AutoML and supply a table with the same eight input
columns. Keep the whole AutoML_Housing directory, including preprocessing
and ensemble dependencies. Use a new results directory for a new experiment.
More about saving and loading.
About the dataset and this recorded run
California Housing describes California census block groups from 1990. The target is a group's median house value, not an individual home's sale price. Its eight inputs include median income, house age and location. The code converts the target from units of $100,000 to dollars.
This example uses a reproducible 5,000-row subset and a random train/test split. For a task involving new regions or later dates, choose validation splits that reflect that task.
The screenshots and scores come from the downloadable script running with MLJAR AutoML 1.4.0, not a mockup. Run details record the environment, metrics and reload check. View the single-model screenshot.
Keep going
| I want to… | Next step |
|---|---|
| Choose a mode and training budget | AutoML modes |
| Train from my own CSV | Concrete-strength tutorial |
| Predict a category | Customer-churn tutorial |
| Try optional neural or foundation models | Available algorithms |
| Share a prediction interface | Prediction apps |
