Skip to main content

Example: House Price Prediction

End-to-end workflow for predicting house prices using XGBoost Regression. Covers dataset prep, training, evaluation, and deploying for inference.

Estimated time: 5-10 minutes
Model: xgboost-regression-gpu
Task: Regression (predict numeric value)


Dataset

Your dataset should have numeric and categorical features with a numeric target column. A typical house prices dataset looks like:

bedrooms,bathrooms,sqft_living,sqft_lot,floors,waterfront,condition,grade,sqft_above,zipcode,price
3,1.0,1180,5650,1,0,3,7,1180,98178,221900
3,2.25,2570,7242,2,0,3,7,2170,98125,538000
2,1.0,770,10000,1,0,3,6,770,98028,180000
4,3.0,1960,5000,1,0,5,7,1050,98136,604000
3,2.0,1680,8080,1,0,3,8,1680,98074,510000

Target column: price (last column by default)


Step 1: Install the SDK

pip install colabhive

Step 2: Initialize Client

import os
from colabhive import ColabHive

client = ColabHive(
api_key=os.getenv("COLABHIVE_API_KEY"),
account_id=os.getenv("COLABHIVE_ACCOUNT_ID"),
base_url="https://api.colabhive.com",
)

Step 3: Upload Dataset

dataset = client.datasets.upload(
name="house_prices",
file="./house_prices.csv",
)

print(f"Dataset ID: {dataset.dataset_id}")
print(f"Samples: {dataset.num_samples}")
print(f"Status: {dataset.status}")

Step 4: Train the Model

job = client.training.create(
model="xgboost-regression-gpu", # GPU-accelerated, 80x faster
dataset_id=dataset.dataset_id,
job_name="house-prices-xgboost",
hyperparameters={
"target_column": "price",
"n_estimators": 500,
"max_depth": 6,
"learning_rate": 0.05,
"subsample": 0.8,
"colsample_bytree": 0.8,
},
)

print(f"Run ID: {job.run_id}")
print(f"Status: {job.status}")

# Wait for completion (polls every 5s, prints progress)
job.wait()

Step 5: Evaluate Results

print("Training complete!")
print(f" R²: {job.metrics.get('r2', 'N/A'):.4f}") # 1.0 = perfect
print(f" MAE: ${job.metrics.get('mae', 'N/A'):,.0f}") # Mean error in $
print(f" RMSE: ${job.metrics.get('rmse', 'N/A'):,.0f}") # Root mean squared error

Expected results on a clean house prices dataset:

  • R² > 0.85 (excellent), > 0.75 (good)
  • MAE < $30,000

If R² < 0.70, try:

  • Increasing n_estimators to 1000
  • Reducing max_depth to 4 (prevents overfitting on small datasets)
  • Adding more feature engineering before upload

Step 6: Register as Inference Endpoint

endpoint = client.training.register_for_inference(
run_id=job.run_id,
name="house-price-predictor",
description="XGBoost model predicting house prices based on property features",
visibility="account", # Private to your team
)

print(f"Endpoint ID: {endpoint.endpoint_id}")
print(f"Status: {endpoint.status}")

Step 7: Run Predictions

# Predict price for a new house
result = client.endpoints.infer(
endpoint_id=endpoint.endpoint_id,
input_data={
"bedrooms": 4,
"bathrooms": 2.5,
"sqft_living": 2200,
"sqft_lot": 6500,
"floors": 2,
"waterfront": 0,
"condition": 4,
"grade": 8,
"sqft_above": 1800,
"zipcode": 98074,
},
)

print(f"Predicted price: ${result['result']:,.0f}")
print(f"Inference time: {result.get('sync_latency_ms', 'N/A')}ms")

Full Script

import os
from colabhive import ColabHive

client = ColabHive(
api_key=os.getenv("COLABHIVE_API_KEY"),
account_id=os.getenv("COLABHIVE_ACCOUNT_ID"),
base_url="https://api.colabhive.com",
)

# 1. Upload
dataset = client.datasets.upload("house_prices", "./house_prices.csv")
print(f"Dataset: {dataset.dataset_id} ({dataset.num_samples} rows)")

# 2. Train
job = client.training.create(
model="xgboost-regression-gpu",
dataset_id=dataset.dataset_id,
job_name="house-prices-xgboost",
hyperparameters={
"target_column": "price",
"n_estimators": 500,
"max_depth": 6,
"learning_rate": 0.05,
},
)
job.wait()
print(f"R²={job.metrics.get('r2', 'N/A'):.3f} | MAE=${job.metrics.get('mae', 0):,.0f}")

# 3. Register
endpoint = client.training.register_for_inference(
run_id=job.run_id,
name="house-price-predictor",
description="XGBoost house price prediction",
visibility="account",
)
print(f"Endpoint: {endpoint.endpoint_id}")

# 4. Predict
result = client.endpoints.infer(
endpoint_id=endpoint.endpoint_id,
input_data={"bedrooms": 4, "bathrooms": 2.5, "sqft_living": 2200,
"sqft_lot": 6500, "floors": 2, "waterfront": 0,
"condition": 4, "grade": 8, "sqft_above": 1800, "zipcode": 98074},
)
print(f"Predicted price: ${result['result']:,.0f}")

Download the Trained Model

If you want to use the model outside ColabHive:

paths = client.training.download(job.run_id, output_dir="./house-price-model")
print("Downloaded:", paths)
# Loads with: import joblib; model = joblib.load("house-price-model/model.pkl")

Next Steps