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


/Users/alexander/anaconda/lib/python3.6/site-packages/sklearn/cross_validation.py:44: DeprecationWarning: This module was deprecated in version 0.18 in favor of the model_selection module into which all the refactored classes and functions are moved. Also note that the interface of the new CV iterators are different from that of this module. This module will be removed in 0.20.
  "This module will be removed in 0.20.", DeprecationWarning)

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))


Accuracy: 67.95%

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()