In [22]:
from sklearn.datasets import load_boston
boston = load_boston()
In [17]:
n = boston.data.shape[0]
n
Out[17]:
Novamente vamos utilizar o número de cômodos para prever o preço do imóvel:
In [23]:
X = boston.data[:,5].reshape(n,1)
y = boston.target
$\mathrm{CV}_{(k)} = \frac{1}{k} \sum_1^k \mathrm{MSE}_k$
In [32]:
from sklearn.linear_model import LinearRegression
from sklearn.cross_validation import cross_val_score
from sklearn.metrics import make_scorer, mean_squared_error
mse = make_scorer(mean_squared_error)
lreg = LinearRegression()
mse_k = cross_val_score(lreg, X, y, cv=10, scoring=mse)
In [33]:
print mse_k
In [34]:
print mse_k.mean()