Advertising.csv数据集——回归树与XGBoost回归

分别使用回归树与XGBoost回归,预测实验三中给出的Advertising.csv数据集,并与传统线性回归预测方法进行比较。

具体要求:

  1. 首先进行数据标准化。
  2. 测试集和训练集比例分别为30%和70%。
  3. 使用均方误差来评价预测的好坏程度。
  4. 对于XGBoost请尝试使用交叉验证找到n_estimators的最优参数值。n_estimators的取值范围为[100-1000]。

 

回归树:

import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeRegressor
from sklearn.metrics import mean_squared_error

train_path = r'Advertising.csv'

def read_train_file(path):
    data = pd.read_csv(path)
    return  data

#回归树
def RegressionTree(data):
    X = data[['TV', 'Radio', 'Newspaper']]
    Y = data['Sales']
    x_train, x_test, y_train, y_test = train_test_split(X, Y, test_size=0.3, random_state=1)

    dt_reg = DecisionTreeRegress
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值