chg fmt to libsvm

This commit is contained in:
tqchen 2014-02-10 21:41:43 -08:00
parent 45a452b27e
commit bf81263301
2 changed files with 19 additions and 12 deletions

View File

@ -13,7 +13,6 @@
// implementations of boosters // implementations of boosters
#include "tree/xgboost_svdf_tree.hpp" #include "tree/xgboost_svdf_tree.hpp"
#include "linear/xgboost_linear.hpp" #include "linear/xgboost_linear.hpp"
#include "../regression/xgboost_reg.h"
namespace xgboost{ namespace xgboost{
namespace booster{ namespace booster{

View File

@ -38,22 +38,30 @@ namespace xgboost{
inline void LoadText( const char* fname, bool silent = false ){ inline void LoadText( const char* fname, bool silent = false ){
data.Clear(); data.Clear();
FILE* file = utils::FopenCheck( fname, "r" ); FILE* file = utils::FopenCheck( fname, "r" );
float label; float label; bool init = true;
int nonzero_dimension; char tmp[ 1024 ];
std::vector<booster::bst_uint> findex; std::vector<booster::bst_uint> findex;
std::vector<booster::bst_float> fvalue; std::vector<booster::bst_float> fvalue;
while( fscanf(file,"%f %d",&label,&nonzero_dimension) == 2 ){ while( fscanf( file, "%s", tmp ) == 1 ){
findex.clear(); fvalue.clear(); unsigned index; float value;
for( int i = 0; i < nonzero_dimension; i++ ){ if( sscanf( tmp, "%u:%f", &index, &value ) == 2 ){
unsigned index; float value; findex.push_back( index ); fvalue.push_back( value );
utils::Assert( fscanf(file, "%d:%f", &index, &value ) == 2, }else{
"The feature dimension is not coincident with the indicated one" ); if( !init ){
findex.push_back(index); fvalue.push_back(value); labels.push_back( label );
data.AddRow( findex, fvalue );
}
findex.clear(); fvalue.clear();
utils::Assert( sscanf( tmp, "%f", &label ) == 1, "invalid format" );
init = false;
} }
data.AddRow( findex, fvalue );
labels.push_back( label );
} }
if( init ){
labels.push_back( label );
data.AddRow( findex, fvalue );
}
this->UpdateInfo(); this->UpdateInfo();
if( !silent ){ if( !silent ){
printf("%ux%u matrix with %lu entries is loaded from %s\n", printf("%ux%u matrix with %lu entries is loaded from %s\n",