使用GBDT模型预测波士顿房价
时间: 2023-11-10 19:07:32 浏览: 181
预测波士顿房价
5星 · 资源好评率100%
使用GBDT模型预测波士顿房价的步骤如下:
```python
# 读取数据
from sklearn.datasets import load_boston
boston = load_boston()
X = boston.data
y = boston.target
# 划分训练集和测试集
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# 导入GBDT模型
from sklearn.ensemble import GradientBoostingRegressor
gbdt = GradientBoostingRegressor()
# 训练模型
gbdt.fit(X_train, y_train)
# 预测测试集
y_pred = gbdt.predict(X_test)
# 评估模型
from sklearn.metrics import mean_squared_error
mse = mean_squared_error(y_test, y_pred)
print("MSE:", mse)
```
相关问题:
阅读全文