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