构建模型与调参
from sklearn.metrics import mean_squared_error
from sklearn.model_selection import train_test_split
print('Training/Fitting ...')
'objective': 'regression',
lgb_train = lgb.Dataset(train_data_x, train_data_y)
lgb_eval = lgb.Dataset(test_data_x, test_data_y, reference=lgb_train)
early_stopping_rounds=50)
y_pred = gbm.predict(test_data_x.values, num_iteration=gbm.best_iteration)
LGBM_mse = mean_squared_error(test_data_y, y_pred)
LGBM_mae = np.mean(abs(test_data_y - y_pred))
print("MSE: %.4f" % LGBM_mse)
print("MSE: %.4f" % LGBM_mae)
from lightgbm import plot_importance
fig,ax = plt.subplots(figsize=(10,8))
plot_importance(gbm,max_num_features=50,ax=ax)