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
db128c8d
Commit
db128c8d
authored
Dec 17, 2016
by
wxchan
Committed by
Guolin Ke
Dec 17, 2016
Browse files
add gridsearch example for python sklearn (#128)
parent
d0b57767
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
1 deletion
+17
-1
examples/python-guide/sklearn_example.py
examples/python-guide/sklearn_example.py
+15
-0
python-package/lightgbm/libpath.py
python-package/lightgbm/libpath.py
+2
-1
No files found.
examples/python-guide/sklearn_example.py
View file @
db128c8d
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
import
lightgbm
as
lgb
import
lightgbm
as
lgb
import
pandas
as
pd
import
pandas
as
pd
from
sklearn.metrics
import
mean_squared_error
from
sklearn.metrics
import
mean_squared_error
from
sklearn.model_selection
import
GridSearchCV
# load or create your dataset
# load or create your dataset
print
(
'Load data...'
)
print
(
'Load data...'
)
...
@@ -34,3 +35,17 @@ print('The rmse of prediction is:', mean_squared_error(y_test, y_pred) ** 0.5)
...
@@ -34,3 +35,17 @@ print('The rmse of prediction is:', mean_squared_error(y_test, y_pred) ** 0.5)
print
(
'Calculate feature importances...'
)
print
(
'Calculate feature importances...'
)
# feature importances
# feature importances
print
(
'Feature importances:'
,
list
(
gbm
.
feature_importance
()))
print
(
'Feature importances:'
,
list
(
gbm
.
feature_importance
()))
# other scikit-learn built-in module
estimator
=
lgb
.
LGBMRegressor
(
num_leaves
=
31
)
param_grid
=
{
'learning_rate'
:
[
0.01
,
0.1
,
1
],
'n_estimators'
:
[
20
,
40
]
}
gbm
=
GridSearchCV
(
estimator
,
param_grid
)
gbm
.
fit
(
X_train
,
y_train
)
print
(
'Best parameters found by grid search are:'
,
gbm
.
best_params_
)
python-package/lightgbm/libpath.py
View file @
db128c8d
...
@@ -25,5 +25,6 @@ def find_lib_path():
...
@@ -25,5 +25,6 @@ def find_lib_path():
dll_path
=
[
os
.
path
.
join
(
p
,
'lib_lightgbm.so'
)
for
p
in
dll_path
]
dll_path
=
[
os
.
path
.
join
(
p
,
'lib_lightgbm.so'
)
for
p
in
dll_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
:
raise
Exception
(
'Cannot find lightgbm Library'
)
dll_path
=
[
os
.
path
.
realpath
(
p
)
for
p
in
dll_path
]
raise
Exception
(
'Cannot find lightgbm Library in following paths: '
+
','
.
join
(
dll_path
))
return
lib_path
return
lib_path
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