cv: fixed devision by zero exception
- show_progress=False or show_progress=0 led to devision by zero exception
This commit is contained in:
parent
9f62553f23
commit
38b773d80b
@ -337,7 +337,8 @@ def aggcv(rlist, show_stdv=True, show_progress=None, as_pandas=True, trial=0):
|
|||||||
if show_progress is None:
|
if show_progress is None:
|
||||||
show_progress = True
|
show_progress = True
|
||||||
|
|
||||||
if (isinstance(show_progress, int) and trial % show_progress == 0) or (isinstance(show_progress, bool) and show_progress):
|
if (isinstance(show_progress, int) and show_progress > 0 and trial % show_progress == 0) or \
|
||||||
|
(isinstance(show_progress, bool) and show_progress):
|
||||||
sys.stderr.write(msg + '\n')
|
sys.stderr.write(msg + '\n')
|
||||||
sys.stderr.flush()
|
sys.stderr.flush()
|
||||||
|
|
||||||
@ -432,10 +433,10 @@ def cv(params, dtrain, num_boost_round=10, nfold=3, metrics=(),
|
|||||||
best_score = score
|
best_score = score
|
||||||
best_score_i = i
|
best_score_i = i
|
||||||
elif i - best_score_i >= early_stopping_rounds:
|
elif i - best_score_i >= early_stopping_rounds:
|
||||||
sys.stderr.write("Stopping. Best iteration: {}\n".format(best_score_i))
|
|
||||||
results = results[:best_score_i+1]
|
results = results[:best_score_i+1]
|
||||||
|
sys.stderr.write("Stopping. Best iteration: {} (mean: {}, std: {})\n".
|
||||||
|
format(best_score_i, results[-1][0], results[-1][1]))
|
||||||
break
|
break
|
||||||
|
|
||||||
if as_pandas:
|
if as_pandas:
|
||||||
try:
|
try:
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user