Skip to content

Commit

Permalink
Merge pull request #2 from tqchen/dev
Browse files Browse the repository at this point in the history
fix loss_type
  • Loading branch information
tqchen committed May 17, 2014
2 parents bf473bd + 3975bf1 commit 85108e6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 0 additions & 2 deletions python/example/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@
i += 1

csr = scipy.sparse.csr_matrix( (dat, (row,col)) )
print 'haha'
dtrain = xgb.DMatrix( csr )
print 'set label'
dtrain.set_label(labels)
evallist = [(dtest,'eval'), (dtrain,'train')]
bst = xgb.train( param, dtrain, num_round, evallist )
Expand Down
17 changes: 11 additions & 6 deletions regrank/xgboost_regrank.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace xgboost{
RegRankBoostLearner(const std::vector<const DMatrix *>& mats){
silent = 0;
obj_ = NULL;
name_obj_ = "reg";
name_obj_ = "reg:linear";
this->SetCacheData(mats);
}
/*!
Expand Down Expand Up @@ -114,7 +114,7 @@ namespace xgboost{
*/
inline void InitModel(void){
base_gbm.InitModel();
mparam.AdjustBase();
mparam.AdjustBase(name_obj_.c_str());
}
/*!
* \brief load model from file
Expand Down Expand Up @@ -308,7 +308,7 @@ namespace xgboost{
/*! \brief constructor */
ModelParam(void){
base_score = 0.5f;
loss_type = 0;
loss_type = -1;
num_feature = 0;
num_class = 0;
memset(reserved, 0, sizeof(reserved));
Expand All @@ -320,14 +320,19 @@ namespace xgboost{
*/
inline void SetParam(const char *name, const char *val){
if (!strcmp("base_score", name)) base_score = (float)atof(val);
if (!strcmp("loss_type", name)) loss_type = atoi(val);
if (!strcmp("num_class", name)) num_class = atoi(val);
if (!strcmp("loss_type", name)) loss_type = atoi(val);
if (!strcmp("bst:num_feature", name)) num_feature = atoi(val);
}
/*!
* \brief adjust base_score
* \brief adjust base_score based on loss type and objective function
*/
inline void AdjustBase(void){
inline void AdjustBase(const char *obj){
// some tweaks for loss type
if( loss_type == -1 ){
loss_type = 1;
if( !strcmp("reg:linear", obj ) ) loss_type = 0;
}
if (loss_type == 1 || loss_type == 2|| loss_type == 3){
utils::Assert(base_score > 0.0f && base_score < 1.0f, "sigmoid range constrain");
base_score = -logf(1.0f / base_score - 1.0f);
Expand Down
1 change: 1 addition & 0 deletions regrank/xgboost_regrank_obj.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace xgboost{
* \param val value of the parameter
*/
virtual void SetParam(const char *name, const char *val) = 0;

/*!
* \brief get gradient over each of predictions, given existing information
* \param preds prediction of current round
Expand Down

0 comments on commit 85108e6

Please sign in to comment.