None
Log lightGBM metrics to neptune¶
Prerequisites¶
Create your dataset and define model parameters.
[ ]:
import lightgbm as lgb
from sklearn.model_selection import train_test_split
from sklearn.datasets import load_wine
data = load_wine()
X_train, X_test, y_train, y_test = train_test_split(data.data, data.target, test_size=0.1)
lgb_train = lgb.Dataset(X_train, y_train)
lgb_eval = lgb.Dataset(X_test, y_test, reference=lgb_train)
params = {'boosting_type': 'gbdt',
'objective': 'multiclass',
'num_class': 3,
'num_leaves': 31,
'learning_rate': 0.05,
'feature_fraction': 0.9
}
Create neptune_monitor
callback¶
[ ]:
import neptune
from neptunecontrib.monitoring.lightgbm import neptune_monitor
neptune.init(project_qualified_name='USER_NAME/PROJECT_NAME')
neptune.create_experiment()
monitor = neptune_monitor()
Add neptune_monitor
callback to lgb.train
¶
[ ]:
gbm = lgb.train(params,
lgb_train,
num_boost_round=500,
valid_sets=[lgb_train, lgb_eval],
valid_names=['train','valid'],
callbacks=[monitor],
)
Stop Neptune experiment¶
[ ]:
neptune.stop()
You can also put everything in the with
block:
[ ]:
with neptune.create_experiment():
...
Monitor your lightGBM training in neptune¶
Now you can watch your lightGBM model training in neptune!
Full lightgbm monitor script¶
[ ]:
import lightgbm as lgb
from sklearn.model_selection import train_test_split
from sklearn.datasets import load_wine
import neptune
from neptunecontrib.monitoring.lightgbm import neptune_monitor
neptune.init(project_qualified_name='USER_NAME/PROJECT_NAME')
data = load_wine()
X_train, X_test, y_train, y_test = train_test_split(data.data, data.target, test_size=0.1)
lgb_train = lgb.Dataset(X_train, y_train)
lgb_eval = lgb.Dataset(X_test, y_test, reference=lgb_train)
params = {'boosting_type': 'gbdt',
'objective': 'multiclass',
'num_class': 3,
'num_leaves': 31,
'learning_rate': 0.05,
'feature_fraction': 0.9
}
with neptune.create_experiment():
monitor = neptune_monitor()
gbm = lgb.train(params,
lgb_train,
num_boost_round=500,
valid_sets=[lgb_train, lgb_eval],
valid_names=['train','valid'],
callbacks=[monitor],
)