当前位置:网站首页>Adaboost使用

Adaboost使用

2022-07-05 08:42:00 python-码博士

from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error
from sklearn.datasets import load_boston
from sklearn.ensemble import AdaBoostClassifier
from sklearn.ensemble import AdaBoostRegressor

# 加载数据
data = load_boston()
# print(data.data)
# print(data.target)

train_x, test_x, train_y, test_y = train_test_split(data.data, data.target, test_size=0.2)
regressor = AdaBoostRegressor()
regressor.fit(train_x,train_y)
pred_y = regressor.predict(test_x)
mse = mean_squared_error(test_y,pred_y)
# print('房价预测结果',pred_y)
print('均方误差 = ',round(mse,2))

# 决策树回归模型
from sklearn.tree import DecisionTreeRegressor

dec_regressor = DecisionTreeRegressor()
dec_regressor.fit(train_x,train_y)
pred_y = dec_regressor.predict(test_x)
mse = mean_squared_error(test_y,pred_y)
# print('房价预测结果',pred_y)
print('决策树均方误差 = ',round(mse,2))

# KNN回归模型
from sklearn.neighbors import KNeighborsRegressor
knn_regressor = KNeighborsRegressor()
knn_regressor.fit(train_x,train_y)
pred_y = knn_regressor.predict(test_x)
mse = mean_squared_error(test_y,pred_y)
# print('房价预测结果',pred_y)
print('KNN均方误差 = ',round(mse,2))
原网站

版权声明
本文为[python-码博士]所创,转载请带上原文链接,感谢
https://blog.csdn.net/m0_54634272/article/details/125609545