模型
lightGBM
sklearn与LightGBM配合使用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 import lightgbm as lgbimport pandas as pdfrom sklearn.metrics import mean_squared_errorfrom sklearn.model_selection import GridSearchCVprint ('加载数据...' )df_train = pd.read_csv('./data/regression.train.txt' , header=None , sep='\t' ) df_test = pd.read_csv('./data/regression.test.txt' , header=None , sep='\t' ) y_train = df_train[0 ].values y_test = df_test[0 ].values X_train = df_train.drop(0 , axis=1 ).values X_test = df_test.drop(0 , axis=1 ).values print ('开始训练...' )gbm = lgb.LGBMRegressor(objective='regression' , num_leaves=31 , learning_rate=0.05 , n_estimators=20 ) gbm.fit(X_train, y_train, eval_set=[(X_test, y_test)], eval_metric='l1' , early_stopping_rounds=5 ) print ('开始预测...' )y_pred = gbm.predict(X_test, num_iteration=gbm.best_iteration_) print ('预测结果的rmse是:' )print (mean_squared_error(y_test, y_pred) ** 0.5 )
lgb.LGBMRegressor参数解释以及调参方法
评价指标
回归评价指标