scikit-learn: regression¶
Gradient-boosted regression on California housing. Records test RMSE and R2; R2 is the claim.
| Framework | scikit-learn |
| Task | Regression |
Install¶
Plus the K-Veritas CLI.
train.py¶
Only the KV lines are new.
import numpy as np
from sklearn.datasets import fetch_california_housing
from sklearn.model_selection import train_test_split
from sklearn.ensemble import HistGradientBoostingRegressor
from sklearn.metrics import mean_squared_error, r2_score
SEED = 42
print(f"KV seed {SEED}")
print("KV phase data")
X, y = fetch_california_housing(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=SEED)
print(f"KV workload dataset_size={len(X_train)} epochs=1 batch_size={len(X_train)}")
print("KV phase train")
model = HistGradientBoostingRegressor(max_iter=300, learning_rate=0.08, random_state=SEED)
model.fit(X_train, y_train)
print("KV phase evaluate")
pred = model.predict(X_test)
rmse = float(np.sqrt(mean_squared_error(y_test, pred)))
r2 = r2_score(y_test, pred)
print(f"KV test_rmse={rmse:.4f}")
print(f"KV test_r2={r2:.4f}")
print(f"KV claim test_r2={r2:.4f}")
print(f"test_rmse={rmse:.4f} test_r2={r2:.4f}", flush=True)
Run it¶
Result¶
R2 about 0.848, RMSE about 0.45 on the held-out split.