XGBoost
所有文档

          全功能AI开发平台 BML

          XGBoost

          XGBoost

          XGBoost框架下,自定义作业支持发布保存模型为picklejoblib格式,并且在发布至模型仓库时需要选择相应的模型文件。使用下面代码进行模型训练时,训练程序可以自行加载数据,训练数据选择空文件夹即可。

          pickle格式示例代码

          # -*- coding:utf-8 -*-
          import xgboost as xgb
          
          
          def save_model(model):
              import pickle
              with open('output/clf.pickle','wb') as f:
                  pickle.dump(model, f)
          
          
          def save_model_joblib(model):
              from sklearn.externals import joblib
              joblib.dump(model, 'output/clf.pkl')
          
          
          rawData = [[2,4],[3,4], [1,2], [4,5], [7,8]]
          label = [6,7,3,9,15]
          
          dtrain = xgb.DMatrix(rawData, label=label)
          deval = xgb.DMatrix([[3,5],[3,6]], label=[8,9])
          
          param = {'max_depth': 2, 'eta': 1, 'silent': 1, 'objective': 'reg:linear'}
          # param['nthread'] = 4
          # param['eval_metric'] = 'auc'
          
          evallist = [(deval, 'eval'), (dtrain, 'train')]
          
          
          num_round = 10
          bst = xgb.train(param, dtrain, num_round, evallist)
          
          dtest = xgb.DMatrix([[2,4], [7,8]])
          ypred = bst.predict(dtest)
          
          print(ypred)
          
          save_model(bst)
          上一篇
          Sklearn
          下一篇
          模型仓库