In [1]:
import matplotlib.pyplot as plt
import numpy as np
import xgboost as xgb
from sklearn.cross_validation import cross_val_score, cross_val_predict
from sklearn.datasets import load_boston
In [2]:
boston = load_boston()
model = xgb.XGBRegressor()
prediction = cross_val_predict(model, boston.data, boston.target, cv=5)
score = cross_val_score(model, boston.data, boston.target, cv=5)
print("Accuracy: {:.2f}%".format(score.mean() * 100))
In [3]:
figure, plot = plt.subplots()
plot.scatter(boston.target, prediction, alpha=0.3, color='yellow')
plot.plot(
[boston.target.min(), boston.target.max()],
[boston.target.min(), boston.target.max()],
'k--', lw=3, color='green'
)
plot.set_xlabel('Measured')
plot.set_ylabel('Prediction')
plt.show()