"python-package/vscode:/vscode.git/clone" did not exist on "1d075f4dda618515490cb1e9bdbd4fa0a4603c8d"
Commit 8c6933ec authored by Tsukasa OMOTO's avatar Tsukasa OMOTO Committed by Guolin Ke
Browse files

fix creating valid_sets (#148)

* fix creating valid_sets

* support both list and dict

* update Python-API.md
parent 7bba0bfc
...@@ -721,11 +721,11 @@ The methods of each Class is in alphabetical order. ...@@ -721,11 +721,11 @@ The methods of each Class is in alphabetical order.
group data of training data group data of training data
eval_set : list, optional eval_set : list, optional
A list of (X, y) tuple pairs to use as a validation set for early-stopping A list of (X, y) tuple pairs to use as a validation set for early-stopping
eval_sample_weight : List of array eval_sample_weight : List or Dict of array
weight of eval data weight of eval data
eval_init_score : List of array eval_init_score : List or Dict of array
init score of eval data init score of eval data
eval_group : List of array eval_group : List or Dict of array
group data of eval data group data of eval data
eval_metric : str, list of str, callable, optional eval_metric : str, list of str, callable, optional
If a str, should be a built-in evaluation metric to use. If a str, should be a built-in evaluation metric to use.
......
...@@ -375,9 +375,21 @@ class LGBMModel(LGBMModelBase): ...@@ -375,9 +375,21 @@ class LGBMModel(LGBMModelBase):
if valid_data[0] is X and valid_data[1] is y: if valid_data[0] is X and valid_data[1] is y:
valid_set = train_set valid_set = train_set
else: else:
valid_weight = None if eval_sample_weight is None else eval_sample_weight.get(i, None) def get_meta_data(collection, i):
valid_init_score = None if eval_init_score is None else eval_init_score.get(i, None) if collection is None:
valid_group = None if eval_group is None else eval_group.get(i, None) return None
elif isinstance(collection, list):
if len(collection) > i:
return collection[i]
else:
return None
elif isinstance(collection, dict):
return collection.get(i, None)
else:
raise TypeError('eval_sample_weight, eval_init_score, and eval_group should be dict or list')
valid_weight = get_meta_data(eval_sample_weight, i)
valid_init_score = get_meta_data(eval_init_score, i)
valid_group = get_meta_data(eval_group, i)
valid_set = _construct_dataset(valid_data[0], valid_data[1], valid_weight, valid_init_score, valid_group, params) valid_set = _construct_dataset(valid_data[0], valid_data[1], valid_weight, valid_init_score, valid_group, params)
valid_sets.append(valid_set) valid_sets.append(valid_set)
......
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