Skip to content

Commit

Permalink
Merge pull request #685 from flust/0.2.x
Browse files Browse the repository at this point in the history
FEA: Add basic framework of 'lightgbm' and merge xgboost and lightgbm…
  • Loading branch information
2017pxy authored Jan 22, 2021
2 parents b6f4f78 + 1cf2b5d commit 8dfc8e5
Show file tree
Hide file tree
Showing 12 changed files with 212 additions and 97 deletions.
2 changes: 1 addition & 1 deletion recbole/config/configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def _load_internal_config_dict(self, model, model_class, dataset):
self.internal_config_dict['MODEL_TYPE'] = model_class.type
if self.internal_config_dict['MODEL_TYPE'] == ModelType.GENERAL:
pass
elif self.internal_config_dict['MODEL_TYPE'] in {ModelType.CONTEXT, ModelType.XGBOOST}:
elif self.internal_config_dict['MODEL_TYPE'] in {ModelType.CONTEXT, ModelType.DECISIONTREE}:
self._update_internal_config_dict(context_aware_init)
if dataset == 'ml-100k':
self._update_internal_config_dict(context_aware_on_ml_100k_init)
Expand Down
2 changes: 1 addition & 1 deletion recbole/data/dataloader/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
from recbole.data.dataloader.context_dataloader import *
from recbole.data.dataloader.sequential_dataloader import *
from recbole.data.dataloader.knowledge_dataloader import *
from recbole.data.dataloader.xgboost_dataloader import *
from recbole.data.dataloader.decisiontree_dataloader import *
from recbole.data.dataloader.user_dataloader import *
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,32 @@
# @Email : [email protected]

"""
recbole.data.dataloader.xgboost_dataloader
recbole.data.dataloader.decisiontree_dataloader
################################################
"""

from recbole.data.dataloader.general_dataloader import GeneralDataLoader, GeneralNegSampleDataLoader, \
GeneralFullDataLoader


class XgboostDataLoader(GeneralDataLoader):
""":class:`XgboostDataLoader` is inherit from
class DecisionTreeDataLoader(GeneralDataLoader):
""":class:`DecisionTreeDataLoader` is inherit from
:class:`~recbole.data.dataloader.general_dataloader.GeneralDataLoader`,
and didn't add/change anything at all.
"""
pass


class XgboostNegSampleDataLoader(GeneralNegSampleDataLoader):
""":class:`XgboostNegSampleDataLoader` is inherit from
class DecisionTreeNegSampleDataLoader(GeneralNegSampleDataLoader):
""":class:`DecisionTreeNegSampleDataLoader` is inherit from
:class:`~recbole.data.dataloader.general_dataloader.GeneralNegSampleDataLoader`,
and didn't add/change anything at all.
"""
pass


class XgboostFullDataLoader(GeneralFullDataLoader):
""":class:`XgboostFullDataLoader` is inherit from
class DecisionTreeFullDataLoader(GeneralFullDataLoader):
""":class:`DecisionTreeFullDataLoader` is inherit from
:class:`~recbole.data.dataloader.general_dataloader.GeneralFullDataLoader`,
and didn't add/change anything at all.
"""
Expand Down
2 changes: 1 addition & 1 deletion recbole/data/dataset/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
from recbole.data.dataset.kg_dataset import KnowledgeBasedDataset
from recbole.data.dataset.social_dataset import SocialDataset
from recbole.data.dataset.kg_seq_dataset import Kg_Seq_Dataset
from recbole.data.dataset.xgboost_dataset import XgboostDataset
from recbole.data.dataset.decisiontree_dataset import DecisionTreeDataset
from recbole.data.dataset.customized_dataset import *
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
# @Email : [email protected]

"""
recbole.data.xgboost_dataset
recbole.data.decisiontree_dataset
##########################
"""

from recbole.data.dataset import Dataset
from recbole.utils import FeatureType


class XgboostDataset(Dataset):
""":class:`XgboostDataset` is based on :class:`~recbole.data.dataset.dataset.Dataset`,
class DecisionTreeDataset(Dataset):
""":class:`DecisionTreeDataset` is based on :class:`~recbole.data.dataset.dataset.Dataset`,
and
Attributes:
Expand Down
14 changes: 7 additions & 7 deletions recbole/data/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ def create_dataset(config):
elif model_type == ModelType.SOCIAL:
from .dataset import SocialDataset
return SocialDataset(config)
elif model_type == ModelType.XGBOOST:
from .dataset import XgboostDataset
return XgboostDataset(config)
elif model_type == ModelType.DECISIONTREE:
from .dataset import DecisionTreeDataset
return DecisionTreeDataset(config)
else:
from .dataset import Dataset
return Dataset(config)
Expand Down Expand Up @@ -283,13 +283,13 @@ def get_data_loader(name, config, eval_setting):
return SequentialNegSampleDataLoader
elif neg_sample_strategy == 'full':
return SequentialFullDataLoader
elif model_type == ModelType.XGBOOST:
elif model_type == ModelType.DECISIONTREE:
if neg_sample_strategy == 'none':
return XgboostDataLoader
return DecisionTreeDataLoader
elif neg_sample_strategy == 'by':
return XgboostNegSampleDataLoader
return DecisionTreeNegSampleDataLoader
elif neg_sample_strategy == 'full':
return XgboostFullDataLoader
return DecisionTreeFullDataLoader
elif model_type == ModelType.KNOWLEDGE:
if neg_sample_strategy == 'by':
if name == 'train':
Expand Down
26 changes: 26 additions & 0 deletions recbole/model/exlib_recommender/lightgbm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# @Time : 2020/1/17
# @Author : Chen Yang
# @Email : [email protected]

r"""
recbole.model.exlib_recommender.lightgbm
#############################
"""

import lightgbm as lgb
from recbole.utils import ModelType, InputType


class lightgbm(lgb.Booster):
r"""lightgbm is inherited from lgb.Booster
"""
type = ModelType.DECISIONTREE
input_type = InputType.POINTWISE

def __init__(self, config, dataset):
super(lgb.Booster, self).__init__()

def to(self, device):
return self
2 changes: 1 addition & 1 deletion recbole/model/exlib_recommender/xgboost.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class xgboost(xgb.Booster):
r"""xgboost is inherited from xgb.Booster
"""
type = ModelType.XGBOOST
type = ModelType.DECISIONTREE
input_type = InputType.POINTWISE

def __init__(self, config, dataset):
Expand Down
23 changes: 23 additions & 0 deletions recbole/properties/model/lightgbm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
convert_token_to_onehot: False
token_num_threshold: 10000

# Dataset
lgb_silent: False

# Train
lgb_model: ~
lgb_params:
boosting: gbdt
num_leaves: 90
min_data_in_leaf: 30
max_depth: -1
learning_rate: 0.1
objective: binary
lambda_l1: 0.1
metric: ['auc', 'binary_logloss']
force_row_wise: True
lgb_learning_rates: ~
lgb_num_boost_round: 300
lgb_early_stopping_rounds: ~
lgb_verbose_eval: 100

11 changes: 0 additions & 11 deletions recbole/properties/model/xgboost.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
# Type of training method
convert_token_to_onehot: False
token_num_threshold: 10000

# DMatrix
xgb_weight: ~
xgb_base_margin: ~
xgb_missing: ~
xgb_silent: ~
xgb_feature_names: ~
xgb_feature_types: ~
xgb_nthread: ~

xgb_model: ~
Expand All @@ -26,11 +20,6 @@ xgb_params:
seed: 2020
# nthread: -1
xgb_num_boost_round: 500
# xgb_evals: ~
xgb_obj: ~
xgb_feval: ~
xgb_maximize: ~
xgb_early_stopping_rounds: ~
# xgb_evals_result: ~
xgb_verbose_eval: 100

Loading

0 comments on commit 8dfc8e5

Please sign in to comment.