chg fmt to libsvm
This commit is contained in:
parent
45a452b27e
commit
bf81263301
@ -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{
|
||||||
|
|||||||
@ -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();
|
|
||||||
for( int i = 0; i < nonzero_dimension; i++ ){
|
|
||||||
unsigned index; float value;
|
unsigned index; float value;
|
||||||
utils::Assert( fscanf(file, "%d:%f", &index, &value ) == 2,
|
if( sscanf( tmp, "%u:%f", &index, &value ) == 2 ){
|
||||||
"The feature dimension is not coincident with the indicated one" );
|
|
||||||
findex.push_back( index ); fvalue.push_back( value );
|
findex.push_back( index ); fvalue.push_back( value );
|
||||||
}
|
}else{
|
||||||
data.AddRow( findex, fvalue );
|
if( !init ){
|
||||||
labels.push_back( label );
|
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();
|
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",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user