本文整理汇总了C++中Forest::saveToFile方法的典型用法代码示例。如果您正苦于以下问题:C++ Forest::saveToFile方法的具体用法?C++ Forest::saveToFile怎么用?C++ Forest::saveToFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Forest
的用法示例。
在下文中一共展示了Forest::saveToFile方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char **argv) {
ArgumentHandler arg_handler(argc, argv);
Forest* forest = 0;
try {
// Handle command line arguments
if (arg_handler.processArguments() != 0) {
return 0;
}
arg_handler.checkArguments();
// Create forest object
switch (arg_handler.treetype) {
case TREE_CLASSIFICATION:
if (arg_handler.probability) {
forest = new ForestProbability;
} else {
forest = new ForestClassification;
}
break;
case TREE_REGRESSION:
forest = new ForestRegression;
break;
case TREE_SURVIVAL:
forest = new ForestSurvival;
break;
case TREE_PROBABILITY:
forest = new ForestProbability;
break;
}
// Verbose output to logfile if non-verbose mode
std::ostream* verbose_out;
if (arg_handler.verbose) {
verbose_out = &std::cout;
} else {
std::ofstream* logfile = new std::ofstream();
logfile->open(arg_handler.outprefix + ".log");
if (!logfile->good()) {
throw std::runtime_error("Could not write to logfile.");
}
verbose_out = logfile;
}
// Call Ranger
*verbose_out << "Starting Ranger." << std::endl;
forest->initCpp(arg_handler.depvarname, arg_handler.memmode, arg_handler.file, arg_handler.mtry,
arg_handler.outprefix, arg_handler.ntree, verbose_out, arg_handler.seed, arg_handler.nthreads,
arg_handler.predict, arg_handler.impmeasure, arg_handler.targetpartitionsize, arg_handler.splitweights,
arg_handler.alwayssplitvars, arg_handler.statusvarname, arg_handler.replace, arg_handler.catvars,
arg_handler.savemem, arg_handler.splitrule);
forest->run(true);
if (arg_handler.write) {
forest->saveToFile();
}
forest->writeOutput();
*verbose_out << "Finished Ranger." << std::endl;
delete forest;
} catch (std::exception& e) {
std::cerr << "Error: " << e.what() << " Ranger will EXIT now." << std::endl;
delete forest;
return -1;
}
return 0;
}