From 8c8dd1a7402ee04ded9f3b6e422f4ea26cff2570 Mon Sep 17 00:00:00 2001 From: tqchen Date: Wed, 12 Mar 2014 17:58:14 -0700 Subject: [PATCH] support int type --- booster/tree/xgboost_tree_model.h | 20 +++++++++++++++++--- regression/xgboost_reg.h | 2 +- utils/xgboost_fmap.h | 6 +++++- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/booster/tree/xgboost_tree_model.h b/booster/tree/xgboost_tree_model.h index fe3a62f15..2b2b636e7 100644 --- a/booster/tree/xgboost_tree_model.h +++ b/booster/tree/xgboost_tree_model.h @@ -346,16 +346,30 @@ namespace xgboost{ const unsigned split_index = nodes[ nid ].split_index(); if( split_index < fmap.size() ){ - if( fmap.type(split_index) == utils::FeatMap::kIndicator ){ + switch( fmap.type(split_index) ){ + case utils::FeatMap::kIndicator:{ int nyes = nodes[ nid ].default_left()?nodes[nid].cright():nodes[nid].cleft(); fprintf( fo, "%d:[%s] yes=%d,no=%d", nid, fmap.name( split_index ), - nyes, nodes[nid].cdefault() ); - }else{ + nyes, nodes[nid].cdefault() ); + break; + } + case utils::FeatMap::kInteger:{ + fprintf( fo, "%d:[%s<%d] yes=%d,no=%d,missing=%d", + nid, fmap.name(split_index), int( float(cond)+1.0f), + nodes[ nid ].cleft(), nodes[ nid ].cright(), + nodes[ nid ].cdefault() ); + break; + } + case utils::FeatMap::kFloat: + case utils::FeatMap::kQuantitive:{ fprintf( fo, "%d:[%s<%f] yes=%d,no=%d,missing=%d", nid, fmap.name(split_index), float(cond), nodes[ nid ].cleft(), nodes[ nid ].cright(), nodes[ nid ].cdefault() ); + break; + } + default: utils::Error("unknown fmap type"); } }else{ fprintf( fo, "%d:[f%u<%f] yes=%d,no=%d,missing=%d", diff --git a/regression/xgboost_reg.h b/regression/xgboost_reg.h index 6238a0d44..2aedf8672 100644 --- a/regression/xgboost_reg.h +++ b/regression/xgboost_reg.h @@ -292,7 +292,7 @@ namespace xgboost{ * \brief adjust base_score */ inline void AdjustBase( void ){ - if( loss_type == 1 ){ + if( loss_type == 1 || loss_type == 2 ){ utils::Assert( base_score > 0.0f && base_score < 1.0f, "sigmoid range constrain" ); base_score = - logf( 1.0f / base_score - 1.0f ); } diff --git a/utils/xgboost_fmap.h b/utils/xgboost_fmap.h index dd7add417..f288d027a 100644 --- a/utils/xgboost_fmap.h +++ b/utils/xgboost_fmap.h @@ -17,7 +17,9 @@ namespace xgboost{ public: enum Type{ kIndicator = 0, - kQuantitive = 1 + kQuantitive = 1, + kInteger = 2, + kFloat = 3 }; public: /*! \brief load feature map from text format */ @@ -54,6 +56,8 @@ namespace xgboost{ inline static Type GetType( const char *tname ){ if( !strcmp( "i", tname ) ) return kIndicator; if( !strcmp( "q", tname ) ) return kQuantitive; + if( !strcmp( "int", tname ) ) return kInteger; + if( !strcmp( "float", tname ) ) return kFloat; utils::Error("unknown feature type, use i for indicator and q for quantity"); return kIndicator; }