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
b423cb47
Unverified
Commit
b423cb47
authored
May 17, 2021
by
sayantan sadhu
Committed by
GitHub
May 16, 2021
Browse files
Improved the syntax of the fstrings (#4294)
parent
d6fc12b3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
6 deletions
+7
-6
tests/c_api_test/test_.py
tests/c_api_test/test_.py
+7
-6
No files found.
tests/c_api_test/test_.py
View file @
b423cb47
...
@@ -29,7 +29,8 @@ def find_lib_path():
...
@@ -29,7 +29,8 @@ def find_lib_path():
lib_path
=
[
p
for
p
in
dll_path
if
os
.
path
.
exists
(
p
)
and
os
.
path
.
isfile
(
p
)]
lib_path
=
[
p
for
p
in
dll_path
if
os
.
path
.
exists
(
p
)
and
os
.
path
.
isfile
(
p
)]
if
not
lib_path
:
if
not
lib_path
:
dll_path
=
[
os
.
path
.
realpath
(
p
)
for
p
in
dll_path
]
dll_path
=
[
os
.
path
.
realpath
(
p
)
for
p
in
dll_path
]
raise
Exception
(
'Cannot find lightgbm library file in following paths:
\n
'
+
'
\n
'
.
join
(
dll_path
))
dll_path_joined
=
'
\n
'
.
join
(
dll_path
)
raise
Exception
(
f
'Cannot find lightgbm library file in following paths:
\n
{
dll_path_joined
}
'
)
return
lib_path
return
lib_path
...
@@ -74,7 +75,7 @@ def load_from_file(filename, reference):
...
@@ -74,7 +75,7 @@ def load_from_file(filename, reference):
LIB
.
LGBM_DatasetGetNumData
(
handle
,
ctypes
.
byref
(
num_data
))
LIB
.
LGBM_DatasetGetNumData
(
handle
,
ctypes
.
byref
(
num_data
))
num_feature
=
ctypes
.
c_long
()
num_feature
=
ctypes
.
c_long
()
LIB
.
LGBM_DatasetGetNumFeature
(
handle
,
ctypes
.
byref
(
num_feature
))
LIB
.
LGBM_DatasetGetNumFeature
(
handle
,
ctypes
.
byref
(
num_feature
))
print
(
'#data:
%d #feature: %d'
%
(
num_data
.
value
,
num_feature
.
value
)
)
print
(
f
'#data:
{
num_data
.
value
}
#feature:
{
num_feature
.
value
}
'
)
return
handle
return
handle
...
@@ -115,7 +116,7 @@ def load_from_csr(filename, reference):
...
@@ -115,7 +116,7 @@ def load_from_csr(filename, reference):
num_feature
=
ctypes
.
c_long
()
num_feature
=
ctypes
.
c_long
()
LIB
.
LGBM_DatasetGetNumFeature
(
handle
,
ctypes
.
byref
(
num_feature
))
LIB
.
LGBM_DatasetGetNumFeature
(
handle
,
ctypes
.
byref
(
num_feature
))
LIB
.
LGBM_DatasetSetField
(
handle
,
c_str
(
'label'
),
c_array
(
ctypes
.
c_float
,
label
),
len
(
label
),
0
)
LIB
.
LGBM_DatasetSetField
(
handle
,
c_str
(
'label'
),
c_array
(
ctypes
.
c_float
,
label
),
len
(
label
),
0
)
print
(
'#data:
%d #feature: %d'
%
(
num_data
.
value
,
num_feature
.
value
)
)
print
(
f
'#data:
{
num_data
.
value
}
#feature:
{
num_feature
.
value
}
'
)
return
handle
return
handle
...
@@ -152,7 +153,7 @@ def load_from_csc(filename, reference):
...
@@ -152,7 +153,7 @@ def load_from_csc(filename, reference):
num_feature
=
ctypes
.
c_long
()
num_feature
=
ctypes
.
c_long
()
LIB
.
LGBM_DatasetGetNumFeature
(
handle
,
ctypes
.
byref
(
num_feature
))
LIB
.
LGBM_DatasetGetNumFeature
(
handle
,
ctypes
.
byref
(
num_feature
))
LIB
.
LGBM_DatasetSetField
(
handle
,
c_str
(
'label'
),
c_array
(
ctypes
.
c_float
,
label
),
len
(
label
),
0
)
LIB
.
LGBM_DatasetSetField
(
handle
,
c_str
(
'label'
),
c_array
(
ctypes
.
c_float
,
label
),
len
(
label
),
0
)
print
(
'#data:
%d #feature: %d'
%
(
num_data
.
value
,
num_feature
.
value
)
)
print
(
f
'#data:
{
num_data
.
value
}
#feature:
{
num_feature
.
value
}
'
)
return
handle
return
handle
...
@@ -186,7 +187,7 @@ def load_from_mat(filename, reference):
...
@@ -186,7 +187,7 @@ def load_from_mat(filename, reference):
num_feature
=
ctypes
.
c_long
()
num_feature
=
ctypes
.
c_long
()
LIB
.
LGBM_DatasetGetNumFeature
(
handle
,
ctypes
.
byref
(
num_feature
))
LIB
.
LGBM_DatasetGetNumFeature
(
handle
,
ctypes
.
byref
(
num_feature
))
LIB
.
LGBM_DatasetSetField
(
handle
,
c_str
(
'label'
),
c_array
(
ctypes
.
c_float
,
label
),
len
(
label
),
0
)
LIB
.
LGBM_DatasetSetField
(
handle
,
c_str
(
'label'
),
c_array
(
ctypes
.
c_float
,
label
),
len
(
label
),
0
)
print
(
'#data:
%d #feature: %d'
%
(
num_data
.
value
,
num_feature
.
value
)
)
print
(
f
'#data:
{
num_data
.
value
}
#feature:
{
num_feature
.
value
}
'
)
return
handle
return
handle
...
@@ -234,7 +235,7 @@ def test_booster():
...
@@ -234,7 +235,7 @@ def test_booster():
ctypes
.
byref
(
out_len
),
ctypes
.
byref
(
out_len
),
result
.
ctypes
.
data_as
(
ctypes
.
POINTER
(
ctypes
.
c_double
)))
result
.
ctypes
.
data_as
(
ctypes
.
POINTER
(
ctypes
.
c_double
)))
if
i
%
10
==
0
:
if
i
%
10
==
0
:
print
(
'%d
iteration test AUC
%f'
%
(
i
,
result
[
0
]
)
)
print
(
f
'
{
i
}
iteration test AUC
{
result
[
0
]
:.
6
f
}
'
)
LIB
.
LGBM_BoosterSaveModel
(
booster
,
0
,
-
1
,
0
,
c_str
(
'model.txt'
))
LIB
.
LGBM_BoosterSaveModel
(
booster
,
0
,
-
1
,
0
,
c_str
(
'model.txt'
))
LIB
.
LGBM_BoosterFree
(
booster
)
LIB
.
LGBM_BoosterFree
(
booster
)
free_dataset
(
train
)
free_dataset
(
train
)
...
...
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