Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
tianlh
LightGBM-DCU
Commits
ed92296d
Commit
ed92296d
authored
Sep 20, 2018
by
Nikita Titov
Committed by
Guolin Ke
Sep 20, 2018
Browse files
[python] use the same zip function in 2 and 3 Python (#1681)
parent
2c5409ba
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
8 deletions
+9
-8
python-package/lightgbm/basic.py
python-package/lightgbm/basic.py
+1
-1
python-package/lightgbm/engine.py
python-package/lightgbm/engine.py
+3
-3
python-package/lightgbm/plotting.py
python-package/lightgbm/plotting.py
+5
-4
No files found.
python-package/lightgbm/basic.py
View file @
ed92296d
...
@@ -251,7 +251,7 @@ def _data_from_pandas(data, feature_name, categorical_feature, pandas_categorica
...
@@ -251,7 +251,7 @@ def _data_from_pandas(data, feature_name, categorical_feature, pandas_categorica
else
:
else
:
if
len
(
cat_cols
)
!=
len
(
pandas_categorical
):
if
len
(
cat_cols
)
!=
len
(
pandas_categorical
):
raise
ValueError
(
'train and valid dataset categorical_feature do not match.'
)
raise
ValueError
(
'train and valid dataset categorical_feature do not match.'
)
for
col
,
category
in
zip
(
cat_cols
,
pandas_categorical
):
for
col
,
category
in
zip
_
(
cat_cols
,
pandas_categorical
):
if
list
(
data
[
col
].
cat
.
categories
)
!=
list
(
category
):
if
list
(
data
[
col
].
cat
.
categories
)
!=
list
(
category
):
data
[
col
]
=
data
[
col
].
cat
.
set_categories
(
category
)
data
[
col
]
=
data
[
col
].
cat
.
set_categories
(
category
)
if
len
(
cat_cols
):
# cat_cols is pandas Index object
if
len
(
cat_cols
):
# cat_cols is pandas Index object
...
...
python-package/lightgbm/engine.py
View file @
ed92296d
...
@@ -12,7 +12,7 @@ import numpy as np
...
@@ -12,7 +12,7 @@ import numpy as np
from
.
import
callback
from
.
import
callback
from
.basic
import
Booster
,
Dataset
,
LightGBMError
,
_InnerPredictor
from
.basic
import
Booster
,
Dataset
,
LightGBMError
,
_InnerPredictor
from
.compat
import
(
SKLEARN_INSTALLED
,
_LGBMGroupKFold
,
_LGBMStratifiedKFold
,
from
.compat
import
(
SKLEARN_INSTALLED
,
_LGBMGroupKFold
,
_LGBMStratifiedKFold
,
integer_types
,
range_
,
string_type
)
integer_types
,
range_
,
zip_
,
string_type
)
def
train
(
params
,
train_set
,
num_boost_round
=
100
,
def
train
(
params
,
train_set
,
num_boost_round
=
100
,
...
@@ -187,7 +187,7 @@ def train(params, train_set, num_boost_round=100,
...
@@ -187,7 +187,7 @@ def train(params, train_set, num_boost_round=100,
booster
=
Booster
(
params
=
params
,
train_set
=
train_set
)
booster
=
Booster
(
params
=
params
,
train_set
=
train_set
)
if
is_valid_contain_train
:
if
is_valid_contain_train
:
booster
.
set_train_data_name
(
train_data_name
)
booster
.
set_train_data_name
(
train_data_name
)
for
valid_set
,
name_valid_set
in
zip
(
reduced_valid_sets
,
name_valid_sets
):
for
valid_set
,
name_valid_set
in
zip
_
(
reduced_valid_sets
,
name_valid_sets
):
booster
.
add_valid
(
valid_set
,
name_valid_set
)
booster
.
add_valid
(
valid_set
,
name_valid_set
)
finally
:
finally
:
train_set
.
_reverse_update_params
()
train_set
.
_reverse_update_params
()
...
@@ -285,7 +285,7 @@ def _make_n_folds(full_data, folds, nfold, params, seed, fpreproc=None, stratifi
...
@@ -285,7 +285,7 @@ def _make_n_folds(full_data, folds, nfold, params, seed, fpreproc=None, stratifi
kstep
=
int
(
num_data
/
nfold
)
kstep
=
int
(
num_data
/
nfold
)
test_id
=
[
randidx
[
i
:
i
+
kstep
]
for
i
in
range_
(
0
,
num_data
,
kstep
)]
test_id
=
[
randidx
[
i
:
i
+
kstep
]
for
i
in
range_
(
0
,
num_data
,
kstep
)]
train_id
=
[
np
.
concatenate
([
test_id
[
i
]
for
i
in
range_
(
nfold
)
if
k
!=
i
])
for
k
in
range_
(
nfold
)]
train_id
=
[
np
.
concatenate
([
test_id
[
i
]
for
i
in
range_
(
nfold
)
if
k
!=
i
])
for
k
in
range_
(
nfold
)]
folds
=
zip
(
train_id
,
test_id
)
folds
=
zip
_
(
train_id
,
test_id
)
ret
=
CVBooster
()
ret
=
CVBooster
()
for
train_idx
,
test_idx
in
folds
:
for
train_idx
,
test_idx
in
folds
:
...
...
python-package/lightgbm/plotting.py
View file @
ed92296d
...
@@ -10,7 +10,8 @@ from io import BytesIO
...
@@ -10,7 +10,8 @@ from io import BytesIO
import
numpy
as
np
import
numpy
as
np
from
.basic
import
Booster
from
.basic
import
Booster
from
.compat
import
MATPLOTLIB_INSTALLED
,
GRAPHVIZ_INSTALLED
,
LGBMDeprecationWarning
,
range_
,
string_type
from
.compat
import
(
MATPLOTLIB_INSTALLED
,
GRAPHVIZ_INSTALLED
,
LGBMDeprecationWarning
,
range_
,
zip_
,
string_type
)
from
.sklearn
import
LGBMModel
from
.sklearn
import
LGBMModel
...
@@ -86,12 +87,12 @@ def plot_importance(booster, ax=None, height=0.2,
...
@@ -86,12 +87,12 @@ def plot_importance(booster, ax=None, height=0.2,
if
not
len
(
importance
):
if
not
len
(
importance
):
raise
ValueError
(
"Booster's feature_importance is empty."
)
raise
ValueError
(
"Booster's feature_importance is empty."
)
tuples
=
sorted
(
zip
(
feature_name
,
importance
),
key
=
lambda
x
:
x
[
1
])
tuples
=
sorted
(
zip
_
(
feature_name
,
importance
),
key
=
lambda
x
:
x
[
1
])
if
ignore_zero
:
if
ignore_zero
:
tuples
=
[
x
for
x
in
tuples
if
x
[
1
]
>
0
]
tuples
=
[
x
for
x
in
tuples
if
x
[
1
]
>
0
]
if
max_num_features
is
not
None
and
max_num_features
>
0
:
if
max_num_features
is
not
None
and
max_num_features
>
0
:
tuples
=
tuples
[
-
max_num_features
:]
tuples
=
tuples
[
-
max_num_features
:]
labels
,
values
=
zip
(
*
tuples
)
labels
,
values
=
zip
_
(
*
tuples
)
if
ax
is
None
:
if
ax
is
None
:
if
figsize
is
not
None
:
if
figsize
is
not
None
:
...
@@ -101,7 +102,7 @@ def plot_importance(booster, ax=None, height=0.2,
...
@@ -101,7 +102,7 @@ def plot_importance(booster, ax=None, height=0.2,
ylocs
=
np
.
arange
(
len
(
values
))
ylocs
=
np
.
arange
(
len
(
values
))
ax
.
barh
(
ylocs
,
values
,
align
=
'center'
,
height
=
height
,
**
kwargs
)
ax
.
barh
(
ylocs
,
values
,
align
=
'center'
,
height
=
height
,
**
kwargs
)
for
x
,
y
in
zip
(
values
,
ylocs
):
for
x
,
y
in
zip
_
(
values
,
ylocs
):
ax
.
text
(
x
+
1
,
y
,
x
,
va
=
'center'
)
ax
.
text
(
x
+
1
,
y
,
x
,
va
=
'center'
)
ax
.
set_yticks
(
ylocs
)
ax
.
set_yticks
(
ylocs
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment