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
b0f7aa50
Commit
b0f7aa50
authored
Jan 12, 2017
by
ClimbsRocks
Browse files
sklearn compatibility update- renames .feature_importance_ to .feature_importances_
parent
6c248d37
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
46 deletions
+46
-46
docs/Python-API.md
docs/Python-API.md
+39
-39
examples/python-guide/sklearn_example.py
examples/python-guide/sklearn_example.py
+1
-1
python-package/lightgbm/sklearn.py
python-package/lightgbm/sklearn.py
+3
-3
tests/python_package_test/test_sklearn.py
tests/python_package_test/test_sklearn.py
+3
-3
No files found.
docs/Python-API.md
View file @
b0f7aa50
...
@@ -796,7 +796,7 @@ The methods of each Class is in alphabetical order.
...
@@ -796,7 +796,7 @@ The methods of each Class is in alphabetical order.
Get the evaluation results.
Get the evaluation results.
####feature_importance_
####feature_importance
s
_
Get normailized feature importances.
Get normailized feature importances.
...
...
examples/python-guide/sklearn_example.py
View file @
b0f7aa50
...
@@ -34,7 +34,7 @@ print('The rmse of prediction is:', mean_squared_error(y_test, y_pred) ** 0.5)
...
@@ -34,7 +34,7 @@ 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
s
_
))
# other scikit-learn modules
# other scikit-learn modules
estimator
=
lgb
.
LGBMRegressor
(
num_leaves
=
31
)
estimator
=
lgb
.
LGBMRegressor
(
num_leaves
=
31
)
...
...
python-package/lightgbm/sklearn.py
View file @
b0f7aa50
...
@@ -463,7 +463,7 @@ class LGBMModel(LGBMModelBase):
...
@@ -463,7 +463,7 @@ class LGBMModel(LGBMModelBase):
return
self
.
evals_result
return
self
.
evals_result
@
property
@
property
def
feature_importance_
(
self
):
def
feature_importance
s
_
(
self
):
"""Get normailized feature importances."""
"""Get normailized feature importances."""
importace_array
=
self
.
booster_
.
feature_importance
().
astype
(
np
.
float32
)
importace_array
=
self
.
booster_
.
feature_importance
().
astype
(
np
.
float32
)
return
importace_array
/
importace_array
.
sum
()
return
importace_array
/
importace_array
.
sum
()
...
@@ -472,9 +472,9 @@ class LGBMModel(LGBMModelBase):
...
@@ -472,9 +472,9 @@ class LGBMModel(LGBMModelBase):
def
booster
(
self
):
def
booster
(
self
):
return
self
.
booster_
return
self
.
booster_
@
LGBMDeprecated
(
'Use attribute feature_importance_ instead.'
)
@
LGBMDeprecated
(
'Use attribute feature_importance
s
_ instead.'
)
def
feature_importance
(
self
):
def
feature_importance
(
self
):
return
self
.
feature_importance_
return
self
.
feature_importance
s
_
class
LGBMRegressor
(
LGBMModel
,
LGBMRegressorBase
):
class
LGBMRegressor
(
LGBMModel
,
LGBMRegressorBase
):
...
...
tests/python_package_test/test_sklearn.py
View file @
b0f7aa50
...
@@ -105,12 +105,12 @@ class TestSklearn(unittest.TestCase):
...
@@ -105,12 +105,12 @@ class TestSklearn(unittest.TestCase):
gbm
=
template
.
test_template
(
return_model
=
True
)
gbm
=
template
.
test_template
(
return_model
=
True
)
gbm_clone
=
clone
(
gbm
)
gbm_clone
=
clone
(
gbm
)
self
.
assertIsInstance
(
gbm
.
booster_
,
lgb
.
Booster
)
self
.
assertIsInstance
(
gbm
.
booster_
,
lgb
.
Booster
)
self
.
assertIsInstance
(
gbm
.
feature_importance_
,
np
.
ndarray
)
self
.
assertIsInstance
(
gbm
.
feature_importance
s
_
,
np
.
ndarray
)
clf
=
template
.
test_template
(
load_digits
(
2
,
True
),
model
=
lgb
.
LGBMClassifier
,
return_model
=
True
)
clf
=
template
.
test_template
(
load_digits
(
2
,
True
),
model
=
lgb
.
LGBMClassifier
,
return_model
=
True
)
self
.
assertListEqual
(
sorted
(
clf
.
classes_
),
[
0
,
1
])
self
.
assertListEqual
(
sorted
(
clf
.
classes_
),
[
0
,
1
])
self
.
assertEqual
(
clf
.
n_classes_
,
2
)
self
.
assertEqual
(
clf
.
n_classes_
,
2
)
self
.
assertIsInstance
(
clf
.
booster_
,
lgb
.
Booster
)
self
.
assertIsInstance
(
clf
.
booster_
,
lgb
.
Booster
)
self
.
assertIsInstance
(
clf
.
feature_importance_
,
np
.
ndarray
)
self
.
assertIsInstance
(
clf
.
feature_importance
s
_
,
np
.
ndarray
)
def
test_joblib
(
self
):
def
test_joblib
(
self
):
gbm
=
template
.
test_template
(
num_round
=
10
,
return_model
=
True
)
gbm
=
template
.
test_template
(
num_round
=
10
,
return_model
=
True
)
...
@@ -118,7 +118,7 @@ class TestSklearn(unittest.TestCase):
...
@@ -118,7 +118,7 @@ class TestSklearn(unittest.TestCase):
gbm_pickle
=
joblib
.
load
(
'lgb.pkl'
)
gbm_pickle
=
joblib
.
load
(
'lgb.pkl'
)
self
.
assertIsInstance
(
gbm_pickle
.
booster_
,
lgb
.
Booster
)
self
.
assertIsInstance
(
gbm_pickle
.
booster_
,
lgb
.
Booster
)
self
.
assertDictEqual
(
gbm
.
get_params
(),
gbm_pickle
.
get_params
())
self
.
assertDictEqual
(
gbm
.
get_params
(),
gbm_pickle
.
get_params
())
self
.
assertListEqual
(
list
(
gbm
.
feature_importance_
),
list
(
gbm_pickle
.
feature_importance_
))
self
.
assertListEqual
(
list
(
gbm
.
feature_importance
s
_
),
list
(
gbm_pickle
.
feature_importance
s
_
))
X_train
,
X_test
,
y_train
,
y_test
=
template
.
test_template
(
return_data
=
True
)
X_train
,
X_test
,
y_train
,
y_test
=
template
.
test_template
(
return_data
=
True
)
gbm
.
fit
(
X_train
,
y_train
,
eval_set
=
[(
X_test
,
y_test
)],
verbose
=
False
)
gbm
.
fit
(
X_train
,
y_train
,
eval_set
=
[(
X_test
,
y_test
)],
verbose
=
False
)
gbm_pickle
.
fit
(
X_train
,
y_train
,
eval_set
=
[(
X_test
,
y_test
)],
verbose
=
False
)
gbm_pickle
.
fit
(
X_train
,
y_train
,
eval_set
=
[(
X_test
,
y_test
)],
verbose
=
False
)
...
...
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