"""Run the Getting started example with mljar-supervised==1.4.0.

Run in a new directory. California Housing downloads on first use and is cached
by scikit-learn. The example uses 5,000 rows, two CPU threads and no GPU.
"""

# docs:example:start
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.
# docs:example:end
