Q:

how to set max_bin params in LightGBM

Following code throws error saying "Unexpected keyword arguemnt 'max_bin'". Later I found 'max_bin' is depreciated. So how can I pass max_bin using 'params'? Can anyone show me a piece of sample code?
lgb.Dataset(x_train, lable=y, max_bin=56)

/anaconda3/lib/python3.6/site-packages/lightgbm/basic.py:648: LGBMDeprecationWarning: The max_bin parameter is deprecated and will
  be removed in 2.0.12 version. Please use params to pass this
  parameter.
      'Please use params to pass this parameter.', LGBMDeprecationWarning)

A:

The params mentioned in the error message refer to the Parameters that are passed to the train() function. If you use the sklearn classes of the python API, some of the parameters are also available as keyword arguments in the classifier's __init__() method.
Example:
import lightgbm as lgb
import numpy as np

from sklearn import datasets
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score

iris = datasets.load_iris()

X_train, X_test, y_train, y_test = train_test_split(iris.data,
                                                    iris.target,
                                                    test_size=0.2)
lgb_train = lgb.Dataset(X_train, y_train)

# here are the parameters you need
params = {
    'task': 'train',
    'boosting_type': 'gbdt',
    'objective': 'multiclass',
    'num_class': 3,
    'max_bin': 4  # <-- max_bin
}

gbm = lgb.train(params,
                lgb_train,
                num_boost_round=20)

y_pred = gbm.predict(X_test, num_iteration=gbm.best_iteration)
y_pred = np.argmax(y_pred, axis=1)
print("Accuracy: ", accuracy_score(y_test, y_pred))

For a detailed example i recommend taking a look at the python examples that come with LGBM.

