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
b8d9372e
Commit
b8d9372e
authored
Nov 24, 2016
by
Guolin Ke
Browse files
Add simple test
parent
629fc047
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
7 deletions
+33
-7
.travis.yml
.travis.yml
+3
-1
python-package/lightgbm/basic.py
python-package/lightgbm/basic.py
+6
-6
tests/python_package_test/test_basic.py
tests/python_package_test/test_basic.py
+24
-0
No files found.
.travis.yml
View file @
b8d9372e
...
@@ -21,9 +21,11 @@ script:
...
@@ -21,9 +21,11 @@ script:
-
cd $TRAVIS_BUILD_DIR
-
cd $TRAVIS_BUILD_DIR
-
mkdir build && cd build && cmake .. && make -j
-
mkdir build && cd build && cmake .. && make -j
-
cd $TRAVIS_BUILD_DIR/tests/c_api_test && python test.py
-
cd $TRAVIS_BUILD_DIR/tests/c_api_test && python test.py
-
cd $TRAVIS_BUILD_DIR/tests/python_package_test && python test_basic.py
-
cd $TRAVIS_BUILD_DIR
-
cd $TRAVIS_BUILD_DIR
-
rm -rf build && mkdir build && cd build && cmake -DUSE_MPI=ON ..&& make -j
-
rm -rf build && mkdir build && cd build && cmake -DUSE_MPI=ON ..&& make -j
-
cd $TRAVIS_BUILD_DIR/tests/c_api_test && python test.py
-
cd $TRAVIS_BUILD_DIR/tests/c_api_test && python test.py
-
cd $TRAVIS_BUILD_DIR/tests/python_package_test && python test_basic.py
notifications
:
notifications
:
email
:
false
email
:
false
...
...
python-package/lightgbm/basic.py
View file @
b8d9372e
...
@@ -290,7 +290,7 @@ class Predictor(object):
...
@@ -290,7 +290,7 @@ class Predictor(object):
n_preds
*=
used_iteration
n_preds
*=
used_iteration
preds
=
np
.
zeros
(
n_preds
,
dtype
=
np
.
float32
)
preds
=
np
.
zeros
(
n_preds
,
dtype
=
np
.
float32
)
out_num_preds
=
ctypes
.
c_int64
(
0
)
out_num_preds
=
ctypes
.
c_int64
(
0
)
_safe_call
(
LIB
.
LGBM_BoosterPredictForMat
(
_safe_call
(
_
LIB
.
LGBM_BoosterPredictForMat
(
self
.
handle
,
self
.
handle
,
ptr_data
,
ptr_data
,
type_ptr_data
,
type_ptr_data
,
...
@@ -324,7 +324,7 @@ class Predictor(object):
...
@@ -324,7 +324,7 @@ class Predictor(object):
ptr_indptr
,
type_ptr_indptr
=
c_int_array
(
csr
.
indptr
)
ptr_indptr
,
type_ptr_indptr
=
c_int_array
(
csr
.
indptr
)
ptr_data
,
type_ptr_data
=
c_float_array
(
csr
.
data
)
ptr_data
,
type_ptr_data
=
c_float_array
(
csr
.
data
)
_safe_call
(
LIB
.
LGBM_BoosterPredictForCSR
(
_safe_call
(
_
LIB
.
LGBM_BoosterPredictForCSR
(
self
.
handle
,
self
.
handle
,
ptr_indptr
,
ptr_indptr
,
type_ptr_indptr
,
type_ptr_indptr
,
...
@@ -447,7 +447,7 @@ class Dataset(object):
...
@@ -447,7 +447,7 @@ class Dataset(object):
init_score
=
new_init_score
init_score
=
new_init_score
self
.
set_init_score
(
init_score
)
self
.
set_init_score
(
init_score
)
def
new_valid_dataset
(
self
,
data
,
label
=
None
,
weight
=
None
,
group_id
=
None
,
def
create_valid
(
self
,
data
,
label
=
None
,
weight
=
None
,
group_id
=
None
,
silent
=
False
,
params
=
None
):
silent
=
False
,
params
=
None
):
"""
"""
Create validation data align with current dataset
Create validation data align with current dataset
...
@@ -487,7 +487,7 @@ class Dataset(object):
...
@@ -487,7 +487,7 @@ class Dataset(object):
data
=
np
.
array
(
mat
.
reshape
(
mat
.
size
),
dtype
=
np
.
float32
)
data
=
np
.
array
(
mat
.
reshape
(
mat
.
size
),
dtype
=
np
.
float32
)
ptr_data
,
type_ptr_data
=
c_float_array
(
data
)
ptr_data
,
type_ptr_data
=
c_float_array
(
data
)
_safe_call
(
LIB
.
LGBM_CreateDatasetFromMat
(
_safe_call
(
_
LIB
.
LGBM_CreateDatasetFromMat
(
ptr_data
,
ptr_data
,
type_ptr_data
,
type_ptr_data
,
mat
.
shape
[
0
],
mat
.
shape
[
0
],
...
@@ -825,7 +825,7 @@ class Booster(object):
...
@@ -825,7 +825,7 @@ class Booster(object):
if
self
.
handle
is
not
None
and
self
.
__is_manage_handle
:
if
self
.
handle
is
not
None
and
self
.
__is_manage_handle
:
_safe_call
(
_LIB
.
LGBM_BoosterFree
(
self
.
handle
))
_safe_call
(
_LIB
.
LGBM_BoosterFree
(
self
.
handle
))
def
add_valid
_data
(
self
,
data
,
name
):
def
add_valid
(
self
,
data
,
name
):
if
data
.
predictor
is
not
self
.
init_predictor
:
if
data
.
predictor
is
not
self
.
init_predictor
:
raise
Exception
(
"Add validation data failed, you should use same predictor for these data"
)
raise
Exception
(
"Add validation data failed, you should use same predictor for these data"
)
_safe_call
(
_LIB
.
LGBM_BoosterAddValidData
(
_safe_call
(
_LIB
.
LGBM_BoosterAddValidData
(
...
@@ -835,7 +835,7 @@ class Booster(object):
...
@@ -835,7 +835,7 @@ class Booster(object):
self
.
name_valid_sets
.
append
(
name
)
self
.
name_valid_sets
.
append
(
name
)
self
.
__num_dataset
+=
1
self
.
__num_dataset
+=
1
def
R
eset
P
arameter
(
self
,
params
,
silent
=
False
):
def
r
eset
_p
arameter
(
self
,
params
,
silent
=
False
):
self
.
__need_reload_eval_info
=
True
self
.
__need_reload_eval_info
=
True
if
silent
:
if
silent
:
params
[
"verbose"
]
=
0
params
[
"verbose"
]
=
0
...
...
tests/python_package_test/test_basic.py
0 → 100644
View file @
b8d9372e
import
numpy
as
np
from
sklearn
import
datasets
,
metrics
,
model_selection
import
importlib.util
spec
=
importlib
.
util
.
spec_from_file_location
(
"module.name"
,
"../../python-package/lightgbm/basic.py"
)
lgb
=
importlib
.
util
.
module_from_spec
(
spec
)
spec
.
loader
.
exec_module
(
lgb
)
X
,
Y
=
datasets
.
make_classification
(
n_samples
=
100000
,
n_features
=
100
)
x_train
,
x_test
,
y_train
,
y_test
=
model_selection
.
train_test_split
(
X
,
Y
,
test_size
=
0.1
)
train_data
=
lgb
.
Dataset
(
x_train
,
max_bin
=
255
,
label
=
y_train
)
valid_data
=
train_data
.
create_valid
(
x_test
,
label
=
y_test
)
config
=
{
"objective"
:
"binary"
,
"metric"
:
"auc"
,
"min_data"
:
1
,
"num_leaves"
:
15
}
bst
=
lgb
.
Booster
(
params
=
config
,
train_set
=
train_data
)
bst
.
add_valid
(
valid_data
,
"valid_1"
)
for
i
in
range
(
100
):
bst
.
update
()
print
(
bst
.
eval_train
())
print
(
bst
.
eval_valid
())
bst
.
save_model
(
"model.txt"
)
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