当前位置:网站首页>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))
边栏推荐
- 287. 寻找重复数-快慢指针
- 剑指 Offer 05. 替换空格
- One dimensional vector transpose point multiplication np dot
- Guess riddles (8)
- Example 004: for the day of the day, enter a day of a month of a year to judge the day of the year?
- 【三层架构及JDBC总结】
- 猜谜语啦(10)
- Some pitfalls of win10 network sharing
- Guess riddles (7)
- [牛客网刷题 Day4] JZ32 从上往下打印二叉树
猜你喜欢

Typescript hands-on tutorial, easy to understand

Daily question - input a date and output the day of the year

Example 006: Fibonacci series

Sword finger offer 09 Implementing queues with two stacks

剑指 Offer 05. 替换空格

猜谜语啦(3)

Halcon affine transformations to regions

猜谜语啦(11)

剑指 Offer 06. 从尾到头打印链表

Example 003: a complete square is an integer. It is a complete square after adding 100, and it is a complete square after adding 168. What is the number?
随机推荐
[three tier architecture]
[matlab] matlab reads and writes Excel
【日常训练】1200. 最小绝对差
Cmder of win artifact
Example 010: time to show
Guess riddles (3)
Five design details of linear regulator
Example 001: the number combination has four numbers: 1, 2, 3, 4. How many three digits can be formed that are different from each other and have no duplicate numbers? How many are each?
Mathematical modeling: factor analysis
How to write cover letter?
剑指 Offer 09. 用两个栈实现队列
剑指 Offer 05. 替换空格
Esphone retrofits old fans
Halcon affine transformations to regions
Guess riddles (142)
Wheel 1:qcustomplot initialization template
Some pitfalls of win10 network sharing
Low code platform | apaas platform construction analysis
[noi simulation] juice tree (tree DP)
Example 002: the bonus paid by the "individual income tax calculation" enterprise is based on the profit commission. When the profit (I) is less than or equal to 100000 yuan, the bonus can be increase