Giter Club home page Giter Club logo

tgboost's Introduction

What is TGBoost

It is a Tiny implement of Gradient Boosting tree, based on XGBoost's scoring function and SLIQ's efficient tree building algorithm. TGBoost build the tree in a level-wise way as in SLIQ (by constructing Attribute list and Class list). Currently, TGBoost support parallel learning on single machine, the speed and memory consumption are comparable to XGBoost.

TGBoost supports most features as other library:

  • Built-in loss , Square error loss for regression task, Logistic loss for classification task

  • Early stopping , evaluate on validation set and conduct early stopping

  • Feature importance , output the feature importance after training

  • Regularization , lambda, gamma

  • Randomness, subsample,colsample

  • Weighted loss function , assign weight to each sample

Another two features are novel:

  • Handle missing value, XGBoost learn a direction for those with missing value, the direction is left or right. TGBoost take a different approach: it enumerate missing value go to left child, right child and missing value child, then choose the best one. So TGBoost use Ternary Tree.

  • Handle categorical feature, TGBoost order the categorical feature by their statistic (Gradient_sum / Hessian_sum) on each tree node, then conduct split finding as numeric feature.

Installation

The current version is implemented in pure Java, to use TGBoost you should first install JDK. For Python user, Python binding is also provided:

git clone [email protected]:wepe/tgboost.git
cd python-package
sudo python setup.py install

To Understand TGBoost

For those want to understand how TGBoost work, and dive into Gradient Boosting Machine, please refer to the Python implementation of TGBoost: tgboost-python, the python source code is relatively easy to follow.

Example

Here is an example, download the data here

import tgboost as tgb

# training phase
ftrain = "data/train.csv"
fval = "data/val.csv"
params = {'categorical_features': ["PRI_jet_num"],
          'early_stopping_rounds': 10,
          'maximize': True,
          'eval_metric': 'auc',
          'loss': 'logloss',
          'eta': 0.3,
          'num_boost_round': 20,
          'max_depth': 7,
          'scale_pos_weight':1.,
          'subsample': 0.8,
          'colsample': 0.8,
          'min_child_weight': 1.,
          'min_sample_split': 5,
          'reg_lambda': 1.,
          'gamma': 0.,
          'num_thread': -1
          }

model = tgb.train(ftrain, fval, params)

# testing phase
ftest = "data/test.csv"
foutput = "data/test_preds.csv"
model.predict(ftest, foutput)

# save the model
model.save('./tgb.model')

# load model and predict
model = tgb.load_model('./tgb.model')
model.predict(ftest, foutput)

Reference

tgboost's People

Contributors

wepe avatar zldeng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tgboost's Issues

关于离散特征处理的问题

现在的代码逻辑,离散特征也会被装箱(bin) 然后就是按照连续特征来处理了。这样的处理,默认离散特征就是有序的了,所以m个特征值有m-1个箱子。但是如果离散特征是无序的,那么箱子数量应该是指数级的。这个地方是不是可以在优化下那?还是说xgboost就是按照无序来处理的?

参考Spark中决策树对于离散特征的处理会先判断离散特征是有序还是无序的,然后在进行装箱。

才疏学浅,很想把大佬的代码吃透了。。。

离散变量该如何split?

代码里this_threshold = (cur_value + nxt_value) / 2.0 如果当前列是离散值 tgboost是不是还不支持?
另外Y.hess.sum() < self.min_child_weight为何用二阶导数的sum作为判定标准没有想明白。谢谢你。

DataSet

Hello Cant download dtaset on Baidu

Try to fix some code in AttributeList.java

The original code is:

    private void initialize_cutting_inds_thresholds(){
        cutting_inds = new int[feature_dim][][];
        cutting_thresholds = new float[feature_dim][];

        for(int i=0;i<feature_dim;i++){
            //for this feature, get its cutting index
            ArrayList<Integer> list = new ArrayList<>();
            int last_index = 0;
            for(int j=0;j<attribute_list[i].length;j++){
                if(attribute_list[i][j][0]==attribute_list[i][last_index][0]){
                    last_index = j;
                }else {
                    list.add(last_index);
                    last_index = j;
                }
            }
            //for this feature,store its cutting threshold
            cutting_thresholds[i] = new float[list.size()+1];
            for(int t=0;t<cutting_thresholds[i].length-1;t++){
                cutting_thresholds[i][t] = attribute_list[i][list.get(t)][0];
            }
            cutting_thresholds[i][list.size()] = attribute_list[i][list.get(list.size()-1)+1][0];

            //for this feature,store inds of each interval
            cutting_inds[i] = new int[list.size()+1][]; //list.size()+1 interval

            list.add(0,-1);
            list.add(attribute_list[i].length-1);
            for(int k=0;k<cutting_inds[i].length;k++){
                int start_ind = list.get(k)+1;
                int end_ind = list.get(k+1);
                cutting_inds[i][k] = new int[end_ind-start_ind+1];
                for(int m=0;m<cutting_inds[i][k].length;m++){
                    cutting_inds[i][k][m] = (int) attribute_list[i][start_ind+m][1];
                }
            }

        }
    }

Edited code is:

      private void initialize_cutting_idx_thresholds() {
		cutting_idx = new int[feature_dim][][];
		cutting_thresholds = new double[feature_dim][];
		
		for (int i = 0; i < feature_dim; ++i) {
			List<Integer> list = new ArrayList<>();
			int last_index = -1;
			for (int j = 0; j < attribute_list[i].length; ++j) {
				if (last_index == -1 || attribute_list[i][j][0] == attribute_list[i][last_index][0]) {
					last_index = j;
				}
				else {
					list.add(last_index);
					last_index = j;
				}
			}
			
			cutting_thresholds[i] = new double[list.size()];
			for (int t = 0; t < cutting_thresholds[i].length; ++t) {
				cutting_thresholds[i][t] = attribute_list[i][list.get(t)][0];
			}
			
			cutting_idx[i] = new int[list.size()][];
			list.add(attribute_list[i].length);
			
			for (int k = 0; k < cutting_idx[i].length; ++k) {
				int s_idx = list.get(k);
				int e_idx = list.get(k + 1);
				cutting_idx[i][k] = new int[e_idx - s_idx];
				for (int m = 0; m < cutting_idx[i][k].length; ++m) {
					cutting_idx[i][k][m] = (int)attribute_list[i][s_idx + m][1];
				}
			}
		}
      }

logistic loss computation

大神,能解释下logistic loss的梯度是怎么计算的吗?
单个样本的logistic loss计算公式是loss(y, x) = log(1 + exp(-y * f(x)) )

其中,f(x)是假设函数, 求导是 -1 / (exp(y*f(x)) + 1) 和你代码中的公式grad = (1-y)/(1-pred) - y/pred对不上那?

是我哪里算错了吗,期待回答

能解释下ClassList和AttributeList命名的意思吗

这两个命名不是很理解,想不通为什么这样叫。能解释下具体的含义吗?非常感谢~ 最近在研究xgboost想把你的开源代码吃透,自己也写写。就是没什么文档,看不太懂。。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.