xgboost入门与实战(实战调参篇)

xgboost入门与实战(实战调参篇)

前言

前面几篇博文都在学习原理知识,是时候上数据上模型跑一跑了。本文用的数据来自kaggle,相信搞机器学习的同学们都知道它,kaggle上有几个老题目一直开放,适合给新手练级,上面还有很多老司机的方案共享以及讨论,非常方便新手入门。这次用的数据是Classify handwritten digits using the famous MNIST data—手写数字识别,每个样本相当于一个图片像素矩阵(28x28),每个像元就是一个特征啦。用这个数据的好处就是不用做特征工程了,对于上手模型很方便。
xgboost安装看这里:http://blog.csdn.net/sb19931201/article/details/52236020

拓展一下:XGBoost Plotting API以及GBDT组合特征实践

数据集

1.数据介绍:数据采用的是广泛应用于机器学习社区的MNIST数据集:

The data for this competition were taken from the MNIST dataset. The MNIST (“Modified National Institute of Standards and Technology”) dataset is a classic within the Machine Learning community that has been extensively studied. More detail about the dataset, including Machine Learning algorithms that have been tried on it and their levels of success, can be found at http://yann.lecun.com/exdb/mnist/index.html.

2.训练数据集(共42000个样本):如下图所示,第一列是label标签,后面共28x28=784个像素特征,特征取值范围为0-255。

3.测试数据集(共28000条记录):就是我们要预测的数据集了,没有标签值,通过train.csv训练出合适的模型,然后根据test.csv的特征数据集来预测这28000的类别(0-9的数字标签)。

4.结果数据样例:两列,一列为ID,一列为预测标签值。

xgboost模型调参、训练(python)

1.导入相关库,读取数据

import numpy as np
import pandas as pd
import xgboost as xgb
from sklearn.cross_validation import train_test_split

#记录程序运行时间
import time 
start_time = time.time()

#读入数据
train = pd.read_csv("Digit_Recognizer/train.csv")
tests = pd.read_csv("Digit_Recognizer/test.csv") 

2.划分数据集

  • 37
    点赞
  • 202
    收藏
    觉得还不错? 一键收藏
  • 17
    评论
xgboost模型的python实战中,我们可以使用xgboost库来构建和训练模型。首先,我们需要定义一个目标函数(objective)来评估模型的性能。在该目标函数中,我们可以指定待优化的函数并设定参/超参数的范围。接下来,我们可以使用单次试验(trial)来执行目标函数,并记录试验结果。最后,我们可以使用研究(study)来管理优化过程,决定优化的方式,包括试验次数和结果记录等功能。通过使用xgboost模型,我们可以根据输入的特征,如房屋总面积、总房间数、浴室数量等,来预测房屋的总价值。这样的模型可以帮助我们更好地理解房屋价值的影响因素,并提供更精确的房屋价格预测。123 #### 引用[.reference_title] - *1* [【项目实战】基于Python实现xgboost回归模型(XGBRegressor)项目实战](https://blog.csdn.net/weixin_42163563/article/details/121110926)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}} ] [.reference_item] - *2* [Python实现基于Optuna超参数自动优化的xgboost回归模型(XGBRegressor算法)项目实战](https://blog.csdn.net/weixin_42163563/article/details/128068041)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}} ] [.reference_item] - *3* [【项目实战Python实现xgboost分类模型(XGBClassifier算法)项目实战](https://blog.csdn.net/weixin_42163563/article/details/121154223)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 17
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值