MCPcopy Create free account
hub / github.com/antmachineintelligence/mtgbmcode / CreateParser

Method CreateParser

src/io/parser.cpp:195–219  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

193}
194
195Parser* Parser::CreateParser(const char* filename, bool header, int num_features, int label_idx) {
196 const int n_read_line = 20;
197 auto lines = ReadKLineFromFile(filename, header, n_read_line);
198 int num_col = 0;
199 DataType type = GetDataType(lines, &num_col);
200 if (type == DataType::INVALID) {
201 Log::Fatal("Unknown format of training data.");
202 }
203 std::unique_ptr<Parser> ret;
204 if (type == DataType::LIBSVM) {
205 label_idx = GetLabelIdxForLibsvm(lines[0], num_features, label_idx);
206 ret.reset(new LibSVMParser(label_idx, num_col));
207 } else if (type == DataType::TSV) {
208 label_idx = GetLabelIdxForTSV(lines[0], num_features, label_idx);
209 ret.reset(new TSVParser(label_idx, num_col));
210 } else if (type == DataType::CSV) {
211 label_idx = GetLabelIdxForCSV(lines[0], num_features, label_idx);
212 ret.reset(new CSVParser(label_idx, num_col));
213 }
214
215 if (label_idx < 0) {
216 Log::Info("Data file %s doesn't contain a label column.", filename);
217 }
218 return ret.release();
219}
220
221} // namespace LightGBM

Callers

nothing calls this directly

Calls 6

resetMethod · 0.80
ReadKLineFromFileFunction · 0.70
GetDataTypeFunction · 0.70
GetLabelIdxForLibsvmFunction · 0.70
GetLabelIdxForTSVFunction · 0.70
GetLabelIdxForCSVFunction · 0.70

Tested by

no test coverage detected