模型调参部分

一,首先说一下训练的大致流程在这里插入图片描述
二,验证方法
1.训练集、线下验证集、线下测试集、线上测试集
2.无时序的数据集:简单划分、交叉验证划分等
3.有时序的数据集:需考虑时序, nested交叉验证划分等
(我认为交叉验证是一个十分好的方法,但需要注意的是交叉验证的折数,因为折数的不同有可能会导致模型的过拟合或者欠拟合)
三,模型
常见的监督学习模型
1.线性模型
2.决策树
3.神经网络
4.支持向量机
5.贝叶斯分类
6.集成学习模型
四,模型选择
1,依据在验证集上的效果选择
2.除了关注效果的均值,还要关注稳健性
3.还需考虑线上效果;可将线上效果视为一折数据
五,调参方法
1,贪心调参

best_obj = dict()
for obj in objective:
    model = LGBMRegressor(objective=obj)
    score = np.mean(cross_val_score(model, X=train_X, y=train_y_ln, verbose=0, cv = 5, scoring=make_scorer(mean_absolute_error)))
    best_obj[obj] = score
    
best_leaves = dict()
for leaves in num_leaves:
    model = LGBMRegressor(objective=min(best_obj.items(), key=lambda x:x[1])[0], num_leaves=leaves)
    score = np.mean(cross_val_score(model, X=train_X, y=train_y_ln, verbose=0, cv = 5, scoring=make_scorer(mean_absolute_error)))
    best_leaves[leaves] = score
    
best_depth = dict()
for depth in max_depth:
    model = LGBMRegressor(objective=min(best_obj.items(), key=lambda x:x[1])[0],
                          num_leaves=min(best_leaves.items(), key=lambda x:x[1])[0],
                          max_depth=depth)
    score = np.mean(cross_val_score(model, X=train_X, y=train_y_ln, verbose=0, cv = 5, scoring=make_scorer(mean_absolute_error)))
    best_depth[depth] = score
sns.lineplot(x=['0_initial','1_turning_obj','2_turning_leaves','3_turning_depth'], y=[0.143 ,min(best_obj.values()), min(best_leaves.values()), min(best_depth.values())])```
	2,Grid调参
			

```python
from sklearn.model_selection import GridSearchCV
parameters = {'objective': objective , 'num_leaves': num_leaves, 'max_depth': max_depth}
model = LGBMRegressor()
clf = GridSearchCV(model, parameters, cv=5)
clf = clf.fit(train_X, train_y)
clf.best_params_`
model = LGBMRegressor(objective='regression',
                          num_leaves=55,
                          max_depth=15)
 np.mean(cross_val_score(model, X=train_X, y=train_y_ln, verbose=0, cv = 5, scoring=make_scorer(mean_absolute_error)))
	3,贝叶斯调参
	

```python

```python
def rf_cv(num_leaves, max_depth, subsample, min_child_samples):
    val = cross_val_score(
        LGBMRegressor(objective = 'regression_l1',
            num_leaves=int(num_leaves),
            max_depth=int(max_depth),
            subsample = subsample,
            min_child_samples = int(min_child_samples)
        ),
        X=train_X, y=train_y_ln, verbose=0, cv = 5, scoring=make_scorer(mean_absolute_error)
    ).mean()
    return 1 - val`rf_bo = BayesianOptimization(
    rf_cv,
    {
    'num_leaves': (2, 100),
    'max_depth': (2, 100),
    'subsample': (0.1, 1),
    'min_child_samples' : (2, 100)
    }
)rf_bo.maximize()`

六,参数调优
1,不建议将精力放在参数调优上;容易过拟合
2.大体的设置参数即可
3.应将精力重点放在特征工程;其次是模型融合
七,个人心得
这次的模型调参部分让我懂得了一些直接没接触过过的知识,不过还有一些东西鄙视太懂,比如L1正则化、L2正则化,之前读西瓜书第一遍的时候,里面有详细介绍过,但时间久了记不太清了,此次也让我认识到了,有些东西需要仔细思考,重复理解,不然读过的东西很快就会忘记。我还知道了打比赛时需要对标签的分布进行查看,看看是否符合正态分布,如果不符合正态分布需要进行相应的转换,比如log转换等,别的什么转换暂时不了解,但我会去查的,还有一点比较神奇的是,绘制学习率曲线和验证曲线,这点之前从未接触到,但我已经懂了它的大致意思,下去会细查的,模型选择与应用没什么好说的,就是直接将lable和data放进模型里,然后调用predict函数,然后就可以了。最后要说的就是调参的那三种方法,贪心调参,网格调参,贝叶斯调参,这对我来说还是比较新鲜的,一位之前没接触过,下去我会好好细细钻研的。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值