当前位置:网站首页>AdaBoost use

AdaBoost use

2022-07-05 08:50:00 Python code doctor

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

#  Load data 
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(' House price forecast ',pred_y)
print(' Mean square error  = ',round(mse,2))

#  Decision tree regression model 
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(' House price forecast ',pred_y)
print(' Mean square error of decision tree  = ',round(mse,2))

# KNN The regression model 
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(' House price forecast ',pred_y)
print('KNN Mean square error  = ',round(mse,2))
原网站

版权声明
本文为[Python code doctor]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/186/202207050841506303.html