CatBoost笔记

实例代码

from catboost import Pool, CatBoostRegressor
# cat_features=[0,2,3,10,11,13,15,16,17,18,19]
from sklearn.model_selection import train_test_split


#X_train_s, X_test_s, y_train_s, y_test_s = train_test_split(X_train_, y_train_, test_size=0.3, random_state=2019)
# train_pool = Pool(X_train_s, y_train_s,cat_features=[0,2,3,10,11,13,15,16,17,18,19])
# val_pool = Pool(X_test_s, y_test_s,cat_features=[0,2,3,10,11,13,15,16,17,18,19])
# test_pool = Pool(X_test_ ,cat_features=[0,2,3,10,11,13,15,16,17,18,19]) 


kfolder = KFold(n_splits=5, shuffle=True, random_state=2019)
oof_cb = np.zeros(len(X_train_))
predictions_cb = np.zeros(len(X_test_))
kfold = kfolder.split(X_train_, y_train_)
fold_=0
#X_train_s, X_test_s, y_train_s, y_test_s = train_test_split(X_train, y_train, test_size=0.3, random_state=2019)
for train_index, vali_index in kfold:
    print("fold n°{}".format(fold_))
    fold_=fold_+1
    k_x_train = X_train[train_index]
    k_y_train = y_train[train_index]
    k_x_vali = X_train[vali_index]
    k_y_vali = y_train[vali_index]
    cb_params = {
         'n_estimators': 100000,
         'loss_function': 'RMSE',
         'eval_metric':'RMSE',
         'learning_rate': 0.05,
         'depth': 5,
         'use_best_model': True,
         'subsample': 0.6,
         'bootstrap_type': 'Bernoulli',
         'reg_lambda': 3
    }
    model_cb = CatBoostRegressor(**cb_params)
    #train the model
    model_cb.fit(k_x_train, k_y_train,eval_set=[(k_x_vali, k_y_vali)],verbose=100,early_stopping_rounds=50)
    oof_cb[vali_index] = model_cb.predict(k_x_vali, ntree_end=model_cb.best_iteration_)
    predictions_cb += model_cb.predict(X_test_, ntree_end=model_cb.best_iteration_) / kfolder.n_splits



print("CV score: {:<8.8f}".format(mean_squared_error(oof_cb, y_train_)))

已标记关键词 清除标记
相关推荐
<p>针对消费金融,现金贷等线上贷款场景,教会学员如何运用python+catboost+lightgbm等算法建立风控模型。</p> <p>实操项目包括</p> <p>(1)美国金融科技公司lendingClub 12万真实数据(分类器模型)</p> <p>(2)移动杯模型竞赛:消费者人群画像-信用智能评分模型竞赛(回归模型)。</p> <p><img src="https://img-bss.csdnimg.cn/202009220407423198.png" alt="" width="885" height="1204" /></p> <p> </p> <p><img src="https://img-bss.csdnimg.cn/202103170335589091.png" alt="" /></p> <p><img src="https://img-bss.csdnimg.cn/202103170338431320.png" alt="" width="884" height="497" /></p> <p><img src="https://img-bss.csdnimg.cn/202103170340349568.png" alt="" width="885" height="502" /></p> <p><img src="https://img-bss.csdnimg.cn/202103170340544465.png" alt="" width="887" height="499" /></p> <p><img src="https://img-bss.csdnimg.cn/202103170341216769.png" alt="" width="888" height="491" /></p> <p><img src="https://img-bss.csdnimg.cn/202009220410147442.png" alt="" width="880" height="978" /></p> <p><img src="https://img-bss.csdnimg.cn/202009220410237645.png" alt="" width="877" height="997" /></p> <p><img src="https://img-bss.csdnimg.cn/202103170341597573.png" alt="" width="882" height="499" /></p> <p><img src="https://img-bss.csdnimg.cn/202103170342127487.png" alt="" width="883" height="495" /></p> <p><img src="https://img-bss.csdnimg.cn/202103170339168322.png" alt="" width="883" height="497" /></p> <p><img src="https://img-bss.csdnimg.cn/202103170339395101.png" alt="" width="879" height="784" /></p>
©️2020 CSDN 皮肤主题: 技术工厂 设计师:CSDN官方博客 返回首页