finish mushroom

This commit is contained in:
tqchen
2014-02-24 23:06:57 -08:00
parent 9d6ef11eb5
commit c4949c0937
8 changed files with 88 additions and 3 deletions

View File

@@ -544,7 +544,11 @@ namespace xgboost{
"input data smaller than num feature" );
int pid = this->GetLeafIndex( feat, funknown, gid );
return tree[ pid ].leaf_value();
}
}
virtual void DumpModel( FILE *fo ){
tree.DumpModel( fo );
}
public:
RTreeTrainer( void ){ silent = 0; }
virtual ~RTreeTrainer( void ){}

View File

@@ -284,6 +284,26 @@ namespace xgboost{
inline int num_extra_nodes( void ) const {
return param.num_nodes - param.num_roots - param.num_deleted;
}
/*! \brief dump model to text file */
inline void DumpModel( FILE *fo ){
this->Dump( 0, fo, 0 );
}
private:
void Dump( int nid, FILE *fo, int depth ){
for( int i = 0; i < depth; ++ i ){
fprintf( fo, "\t" );
}
if( nodes[ nid ].is_leaf() ){
fprintf( fo, "%d:leaf=%f\n", nid, nodes[ nid ].leaf_value() );
}else{
// right then left,
TSplitCond cond = nodes[ nid ].split_cond();
fprintf( fo, "%d:[f%u>%f] yes=%d,no=%d\n", nid,
nodes[ nid ].split_index(), float(cond), nodes[ nid ].cright(), nodes[ nid ].cleft() );
this->Dump( nodes[ nid ].cright(), fo, depth+1 );
this->Dump( nodes[ nid ].cleft(), fo, depth+1 );
}
}
};
};