资源简介
亲自已测可以直接使用安装的LightGBM包,希望帮助不想安装vs的小伙伴们安装python包/
代码片段和文件信息
# coding: utf-8
# pylint: disable = invalid-name C0111
import lightgbm as lgb
import pandas as pd
import numpy as np
# load or create your dataset
print(‘Load data...‘)
df_train = pd.read_csv(‘../binary_classification/binary.train‘ header=None sep=‘\t‘)
df_test = pd.read_csv(‘../binary_classification/binary.test‘ header=None sep=‘\t‘)
W_train = pd.read_csv(‘../binary_classification/binary.train.weight‘ header=None)[0]
W_test = pd.read_csv(‘../binary_classification/binary.test.weight‘ header=None)[0]
y_train = df_train[0].values
y_test = df_test[0].values
X_train = df_train.drop(0 axis=1).values
X_test = df_test.drop(0 axis=1).values
num_train num_feature = X_train.shape
# create dataset for lightgbm
# if you want to re-use data remember to set free_raw_data=False
lgb_train = lgb.Dataset(X_train y_train
weight=W_train free_raw_data=False)
lgb_eval = lgb.Dataset(X_test y_test reference=lgb_train
weight=W_test free_raw_data=False)
# specify your configurations as a dict
params = {
‘boosting_type‘: ‘gbdt‘
‘objective‘: ‘binary‘
‘metric‘: ‘binary_logloss‘
‘num_leaves‘: 31
‘learning_rate‘: 0.05
‘feature_fraction‘: 0.9
‘bagging_fraction‘: 0.8
‘bagging_freq‘: 5
‘verbose‘: 0
}
# generate a feature name
feature_name = [‘feature_‘ + str(col) for col in range(num_feature)]
print(‘Start training...‘)
# feature_name and categorical_feature
gbm = lgb.train(params
lgb_train
num_boost_round=10
valid_sets=lgb_train # eval training data
feature_name=feature_name
categorical_feature=[21])
# check feature name
print(‘Finish first 10 rounds...‘)
print(‘7th feature name is:‘ repr(lgb_train.feature_name[6]))
# save model to file
gbm.save_model(‘model.txt‘)
# continue training
# init_model accepts:
# 1. model file name
# 2. Booster()
gbm = lgb.train(params
lgb_train
num_boost_round=10
init_model=‘model.txt‘
valid_sets=lgb_eval)
print(‘Finish 10 - 20 rounds with model file...‘)
# decay learning rates
# learning_rates accepts:
# 1. list/tuple with length = num_boost_round
# 2. function(curr_iter)
gbm = lgb.train(params
lgb_train
num_boost_round=10
init_model=gbm
learning_rates=lambda iter: 0.05 * (0.99 ** iter)
valid_sets=lgb_eval)
print(‘Finish 20 - 30 rounds with decay learning rates...‘)
# change other parameters during training
gbm = lgb.train(params
lgb_train
num_boost_round=10
init_model=gbm
valid_sets=lgb_eval
callbacks=[lgb.reset_parameter(bagging_fraction=[0.7] * 5 + [0.6] * 5)])
print(‘Finish 30 - 40 rounds with changing bagging_frac
相关资源
- python机器学习Sebastian Raschka中文最新完
- Python-DeepMoji模型的pyTorch实现
- 《机器学习实战》源代码Python3
- Python-使用DeepFakes实现YouTube视频自动换
- Introduction to machine learning with python (
- python新浪微博爬虫,爬取微博和用户
- Python-一系列高品质的动漫人脸数据集
- Python-Insightface人脸检测识别的最小化
- 非线性回归Python代码
- 093 2018北风网人工智能视频(完结)转
- python的色情图片识别
- 贝叶斯网络程序
- 《机器学习实战》Python3代码
- Python-自然场景文本检测PSENet的一个
- Python-在特征金字塔网络FPN的Pytorch实现
- Python-PyTorch实时多人姿态估计项目的实
- Python-用PyTorch10实现FasterRCNN和MaskRCNN比
- Python-心脏核磁共振MRI图像分割
- Python-基于YOLOv3的行人检测
- Python-RLSeq2Seq用于SequencetoSequence模型的
- Python-PyTorch对卷积CRF的参考实现
- Python-高效准确的EAST文本检测器的一个
- Python-pytorch实现的人脸检测和人脸识别
- Python-UNet用于医学图像分割的嵌套UN
- Python-TensorFlow弱监督图像分割
- Python-基于tensorflow实现的用textcnn方法
- Python-Keras实现Inceptionv4InceptionResnetv1和
- Python-pytorch中文手册
- Python-FastSCNN的PyTorch实现快速语义分割
- Python-滑动窗口高分辨率显微镜图像分
评论
共有 条评论