机器学习-监督学习 房价预测问题```
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error
import numpy as np
X_size = [2104, 1600, 2400, 1416, 3000]
X_room = [3, 3, 3, 2, 4]
X_train = np.array(X_size + X_room).reshape((len(X_size), 2), order="F")
noise = np.random.randn(5, 1)
noise = noise - np.mean(noise)
Y_price = np.array([400, 330, 369, 232, 540])
Y_train = Y_price+noise
Y_train = np.array(Y_price).reshape((len(Y_price), 1))
lr = LinearRegression()
lr.fit(X_train, Y_train)
Y_predict = lr.predict(X_train)
error = mean_squared_error(Y_train, Y_predict)
print("预测误差为:", error)
a_arr = lr.coef_[0]
b = lr.intercept_[0]
print("系数一系数二分别为", a_arr)
print("截距为", b)
|