Commit 7287af3e authored by Guolin Ke's avatar Guolin Ke
Browse files

change no_limit to <=0. fix float in is_1d_list.

parent 28e891ad
......@@ -365,7 +365,7 @@ DllExport int LGBM_BoosterGetPredict(BoosterHandle handle,
* 0:normal, with transform (if needed)
* 1:raw score
* 2:leaf index
* \param num_iteration number of iteration for prediction, < 0 means no limit
* \param num_iteration number of iteration for prediction, <= 0 means no limit
* \param result_filename filename of result file
* \return 0 when succeed, -1 when failure happens
*/
......@@ -391,7 +391,7 @@ DllExport int LGBM_BoosterPredictForFile(BoosterHandle handle,
* 0:normal, with transform (if needed)
* 1:raw score
* 2:leaf index
* \param num_iteration number of iteration for prediction, < 0 means no limit
* \param num_iteration number of iteration for prediction, <= 0 means no limit
* \param out_len len of output result
* \param out_result used to set a pointer to array, should allocate memory before call this function
* \return 0 when succeed, -1 when failure happens
......@@ -422,7 +422,7 @@ DllExport int LGBM_BoosterPredictForCSR(BoosterHandle handle,
* 0:normal, with transform (if needed)
* 1:raw score
* 2:leaf index
* \param num_iteration number of iteration for prediction, < 0 means no limit
* \param num_iteration number of iteration for prediction, <= 0 means no limit
* \param out_len len of output result
* \param out_result used to set a pointer to array, should allocate memory before call this function
* \return 0 when succeed, -1 when failure happens
......@@ -441,7 +441,7 @@ DllExport int LGBM_BoosterPredictForMat(BoosterHandle handle,
/*!
* \brief save model into file
* \param handle handle
* \param num_iteration, < 0 means no limit
* \param num_iteration, <= 0 means save all
* \param filename file name
* \return 0 when succeed, -1 when failure happens
*/
......
......@@ -99,7 +99,7 @@ public:
std::string output_result = "LightGBM_predict_result.txt";
std::string input_model = "";
int verbosity = 1;
int num_iteration_predict = NO_LIMIT;
int num_iteration_predict = -1;
bool is_pre_partition = false;
bool is_enable_sparse = true;
bool use_two_round_loading = false;
......@@ -166,12 +166,12 @@ public:
int feature_fraction_seed = 2;
double feature_fraction = 1.0f;
// max cache size(unit:MB) for historical histogram. < 0 means not limit
double histogram_pool_size = NO_LIMIT;
double histogram_pool_size = -1.0f;
// max depth of tree model.
// Still grow tree by leaf-wise, but limit the max depth to avoid over-fitting
// And the max leaves will be min(num_leaves, pow(2, max_depth - 1))
// max_depth < 0 means not limit
int max_depth = NO_LIMIT;
int max_depth = -1;
void Set(const std::unordered_map<std::string, std::string>& params) override;
};
......
......@@ -24,7 +24,6 @@ using ReduceFunction = std::function<void(const char*, char*, int)>;
using PredictFunction =
std::function<std::vector<double>(const std::vector<std::pair<int, double>>&)>;
#define NO_LIMIT (-1)
#define NO_SPECIFIC (-1)
} // namespace LightGBM
......
......@@ -82,7 +82,7 @@ def is_1d_list(data):
if not isinstance(data, list):
return False
if len(data) > 0:
if not isinstance(data[0], (int, str, bool) ):
if not isinstance(data[0], (int, float, bool) ):
return False
return True
......
......@@ -226,9 +226,8 @@ void Application::Train() {
Log::Info("%f seconds elapsed, finished iteration %d", std::chrono::duration<double,
std::milli>(end_time - start_time) * 1e-3, iter + 1);
}
is_finished = true;
// save model to file
boosting_->SaveModelToFile(NO_LIMIT, config_.io_config.output_model.c_str());
boosting_->SaveModelToFile(-1, config_.io_config.output_model.c_str());
Log::Info("Finished training");
}
......
......@@ -414,12 +414,12 @@ void GBDT::SaveModelToFile(int num_iteration, const char* filename) const {
output_file << std::endl;
int num_used_model = 0;
if (num_iteration == NO_LIMIT) {
if (num_iteration <= 0) {
num_used_model = static_cast<int>(models_.size());
} else {
num_used_model = num_iteration * num_class_;
}
num_used_model = std::min(num_used_model, static_cast<int>(models_.size()));
// output tree models
for (int i = 0; i < num_used_model; ++i) {
output_file << "Tree=" << i << std::endl;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment