Boston House Price with Scikit-Learn
Boston House Price with Scikit-Learn
Data Description
>>> from sklearn.datasets import load_boston
>>> boston = load_boston()
>>> x, y = boston.data, boston.target
>>> print(x.shape)
(506, 13)
>>> print(y.shape)
(506,)
Regression with Linear Regression Model
# encoding:utf8
from sklearn.datasets import load_boston
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error, mean_absolute_error
if __name__ == '__main__':
boston = load_boston()
x, y = boston.data, boston.target
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2)
model = LinearRegression()
model.fit(x_train, y_train)
y_pred = model.predict(x_test)
print("mse: %f" % mean_squared_error(y_test, y_pred))
print("mae: %f" % mean_absolute_error(y_test, y_pred))
智慧在街市上呼喊,在宽阔处发声。