chg fmt to libsvm
This commit is contained in:
parent
45a452b27e
commit
bf81263301
@ -13,7 +13,6 @@
|
||||
// implementations of boosters
|
||||
#include "tree/xgboost_svdf_tree.hpp"
|
||||
#include "linear/xgboost_linear.hpp"
|
||||
#include "../regression/xgboost_reg.h"
|
||||
|
||||
namespace xgboost{
|
||||
namespace booster{
|
||||
|
||||
@ -38,22 +38,30 @@ namespace xgboost{
|
||||
inline void LoadText( const char* fname, bool silent = false ){
|
||||
data.Clear();
|
||||
FILE* file = utils::FopenCheck( fname, "r" );
|
||||
float label;
|
||||
int nonzero_dimension;
|
||||
float label; bool init = true;
|
||||
char tmp[ 1024 ];
|
||||
std::vector<booster::bst_uint> findex;
|
||||
std::vector<booster::bst_float> fvalue;
|
||||
|
||||
while( fscanf(file,"%f %d",&label,&nonzero_dimension) == 2 ){
|
||||
findex.clear(); fvalue.clear();
|
||||
for( int i = 0; i < nonzero_dimension; i++ ){
|
||||
while( fscanf( file, "%s", tmp ) == 1 ){
|
||||
unsigned index; float value;
|
||||
utils::Assert( fscanf(file, "%d:%f", &index, &value ) == 2,
|
||||
"The feature dimension is not coincident with the indicated one" );
|
||||
if( sscanf( tmp, "%u:%f", &index, &value ) == 2 ){
|
||||
findex.push_back( index ); fvalue.push_back( value );
|
||||
}
|
||||
data.AddRow( findex, fvalue );
|
||||
}else{
|
||||
if( !init ){
|
||||
labels.push_back( label );
|
||||
data.AddRow( findex, fvalue );
|
||||
}
|
||||
findex.clear(); fvalue.clear();
|
||||
utils::Assert( sscanf( tmp, "%f", &label ) == 1, "invalid format" );
|
||||
init = false;
|
||||
}
|
||||
}
|
||||
if( init ){
|
||||
labels.push_back( label );
|
||||
data.AddRow( findex, fvalue );
|
||||
}
|
||||
|
||||
this->UpdateInfo();
|
||||
if( !silent ){
|
||||
printf("%ux%u matrix with %lu entries is loaded from %s\n",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user