"tests/git@developer.sourcefind.cn:tianlh/lightgbm-dcu.git" did not exist on "6d4c7b03b7273f23b913406cc9c9d85d5178b373"
Commit db128c8d authored by wxchan's avatar wxchan Committed by Guolin Ke
Browse files

add gridsearch example for python sklearn (#128)

parent d0b57767
......@@ -3,6 +3,7 @@
import lightgbm as lgb
import pandas as pd
from sklearn.metrics import mean_squared_error
from sklearn.model_selection import GridSearchCV
# load or create your dataset
print('Load data...')
......@@ -34,3 +35,17 @@ print('The rmse of prediction is:', mean_squared_error(y_test, y_pred) ** 0.5)
print('Calculate feature importances...')
# feature importances
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_)
......@@ -25,5 +25,6 @@ def find_lib_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)]
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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment