房价模型构建实战(四)——模型选择

本文通过GridSearch对XGBoost模型进行参数调优,选取了n_estimators, max_depth, min_child_weight, gamma, subsample, colsample_bytree等关键参数进行调整。最终确定的最佳参数组合显著提高了模型的预测准确性,降低了误差,表明调参对模型性能有显著提升。" 115538521,7688847,微信支付H5退款接口详解,"['微信支付', '退款', 'API接口', 'Java开发', '支付集成']
摘要由CSDN通过智能技术生成

我们使用GridSearch对xgboost进行调参。首先先导入我们需要使用的包。

from sklearn.model_selection import GridSearchCV
from sklearn.model_selection import KFold, cross_val_score
import xgboost as xgb

我们通过以前主观判断和以前的经验来挑选出一些重要的参数,并将他们设置为默认值。

other_params = {
   'eta': 0.3, 'n_estimators': 850, 'gamma': 0, 'max_depth': 5, 'min_child_weight': 3,
                'colsample_bytree': 1, 'colsample_bylevel': 1, 'subsample': 1, 'reg_lambda': 1, 'reg_alpha': 0,
                'seed': 33}

然后我们将数据集划分为测试机和训练集。

X = train
y = X.pop('tradeMoney')
X_train_full,X_valid_full,y_train,y_valid = train_test_split(X,y,train_size=0.8,test_size=0.2,
                                                   random_state=0)

1.寻找最佳的 n_estimators

cv_params = {
   'n_estimators': np.linspace(100, 1000, 10, dtype=int)}
regress_model = xgb.XGBRegressor(**other_params) 
gs = GridSearchCV(regress_model, cv_params, verbose=2, refit=True, cv=5, n_jobs=-1)
gs.fit(X_train_full, y_train)  
print("参数的最佳取值::", gs.best_params_)
print("最佳模型得分:", gs.best_score_
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值