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
d800a4e3
Commit
d800a4e3
authored
Dec 27, 2016
by
wxchan
Committed by
Guolin Ke
Dec 27, 2016
Browse files
add is_numeric (#143)
parent
a6f4ed3d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
1 deletion
+9
-1
python-package/lightgbm/basic.py
python-package/lightgbm/basic.py
+9
-1
No files found.
python-package/lightgbm/basic.py
View file @
d800a4e3
...
@@ -58,6 +58,14 @@ def is_str(s):
...
@@ -58,6 +58,14 @@ def is_str(s):
else
:
else
:
return
isinstance
(
s
,
basestring
)
return
isinstance
(
s
,
basestring
)
def
is_numeric
(
obj
):
"""Check is a number or not, include numpy number etc."""
try
:
float
(
obj
)
return
True
except
:
return
False
def
is_numpy_object
(
data
):
def
is_numpy_object
(
data
):
"""Check is numpy object"""
"""Check is numpy object"""
return
type
(
data
).
__module__
==
np
.
__name__
return
type
(
data
).
__module__
==
np
.
__name__
...
@@ -116,7 +124,7 @@ def param_dict_to_str(data):
...
@@ -116,7 +124,7 @@ def param_dict_to_str(data):
for
key
,
val
in
data
.
items
():
for
key
,
val
in
data
.
items
():
if
isinstance
(
val
,
(
list
,
tuple
,
set
))
or
is_numpy_1d_array
(
val
):
if
isinstance
(
val
,
(
list
,
tuple
,
set
))
or
is_numpy_1d_array
(
val
):
pairs
.
append
(
str
(
key
)
+
'='
+
','
.
join
(
map
(
str
,
val
)))
pairs
.
append
(
str
(
key
)
+
'='
+
','
.
join
(
map
(
str
,
val
)))
elif
is_str
(
val
)
or
isinstance
(
val
,
(
int
,
float
,
bool
))
or
is_num
py_object
(
val
):
elif
is_str
(
val
)
or
isinstance
(
val
,
(
int
,
float
,
bool
))
or
is_num
eric
(
val
):
pairs
.
append
(
str
(
key
)
+
'='
+
str
(
val
))
pairs
.
append
(
str
(
key
)
+
'='
+
str
(
val
))
else
:
else
:
raise
TypeError
(
'Unknown type of parameter:%s, got:%s'
raise
TypeError
(
'Unknown type of parameter:%s, got:%s'
...
...
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