python package : https://github.com/mwburke/xgboost-python-deploy

import xgboost as xgb
import numpy as np
import pandas as pd
from xgb_deploy.fmap import generate_fmap_from_pandas
from xgb_deploy.model import ProdEstimator
from sklearn.model_selection import train_test_split
import json
import random dim_float = 80
dim_int = 20
n = 50000 df_float = pd.DataFrame(np.random.rand(n,dim_float))
df_float.columns = ['float_%s'%i for i in range(dim_float)]
df_int = pd.DataFrame(np.random.randint(0,10,size=(n,dim_int)))
df_int.columns = ['int_%s'%i for i in range(dim_int)]
feature_cols = list(df_float.columns)+list(df_int.columns)
df_data = pd.concat([df_float,df_int],axis=1)
df_data['label'] = np.random.randint(0,2,n)
print(df_data['label'].value_counts())
print(df_data.shape)
print(df_data.head(5)) generate_fmap_from_pandas(df_data, 'demo_fmap.txt') X_train, X_test, y_train, y_test = train_test_split(df_data[feature_cols], df_data['label'], test_size=0.33) dtrain = xgb.DMatrix(data=X_train, label=y_train)
dtest = xgb.DMatrix(data=X_test, label=y_test) classification_params = {
'base_score': 0.5, # np.mean(y_train),
'max_depth': 3,
'eta': 0.1,
'objective': 'binary:logistic',
'eval_metric': 'auc',
'silent': 1,
'n_jobs ':-1
} clf = xgb.XGBClassifier(**classification_params)
clf.fit(X_train, y_train,eval_set=[(X_train, y_train), (X_test, y_test)],eval_metric='logloss',verbose=True)
X_test['pred1'] = clf.predict_proba(X_test)[:,1]
model = clf._Booster model.dump_model(fout='demo_xgb.json', fmap='demo_fmap.txt', dump_format='json') with open('demo_xgb.json', 'r') as f:
model_data = json.load(f) estimator = ProdEstimator(model_data, pred_type='classification', base_score=classification_params['base_score'])
X_test['pred2'] = estimator.predict(X_test.to_dict(orient='records'))
X_test['diff'] = X_test['pred1'] - X_test['pred2']
print(X_test[['pred1','pred2','diff']].head(30))
print(X_test['diff'].sum())
      pred1     pred2          diff

33243 0.515672 0.515672 1.635301e-08

15742 0.478694 0.478694 3.468678e-08

24815 0.596091 0.596091 -5.536898e-09

33120 0.489696 0.489696 4.128085e-08

29388 0.472804 0.472804 -6.701184e-09

33662 0.478668 0.478668 1.495377e-08

15019 0.495415 0.495415 -1.104315e-09

7787 0.555280 0.555280 -1.022957e-08

39378 0.494439 0.494439 5.891659e-08

15317 0.481563 0.481563 1.630472e-08

31946 0.533403 0.533403 -2.231835e-08

16784 0.484454 0.484454 2.196223e-08

13511 0.529494 0.529494 -2.274838e-09

11304 0.492583 0.492583 -1.724794e-09

9583 0.501279 0.501279 -1.815183e-09

31448 0.517019 0.517019 -2.593171e-08

38030 0.482880 0.482880 -1.191063e-08

49734 0.479614 0.479614 -1.770112e-08

15682 0.479675 0.479675 4.876058e-09

30756 0.539753 0.539753 9.885628e-09

4829 0.507685 0.507685 2.341456e-08

49888 0.502952 0.502952 2.951946e-08

41311 0.500395 0.500395 1.270836e-08

22434 0.486226 0.486226 1.047917e-08

45807 0.531456 0.531457 -3.217818e-08

25009 0.490071 0.490071 2.752955e-08

3419 0.516763 0.516763 -2.142890e-09

18176 0.486686 0.486686 -5.403653e-09

18296 0.490275 0.490275 -3.624349e-08

314 0.496112 0.496112 -1.507733e-08

-0.05263647978160496

xgboost load model from demp text file的更多相关文章

  1. unity, read text file

    using System.IO; //test read txt        //Resources.Load(...) loads an asset stored at path in a Res ...

  2. [转]Loading, Editing, and Saving a Text File in HTML5 Using Javascript

    本文转自:http://thiscouldbebetter.wordpress.com/2012/12/18/loading-editing-and-saving-a-text-file-in-htm ...

  3. shell脚本执行时报"bad interpreter: Text file busy"的解决方法

    在执行一个shell脚本时,遇到了“-bash: ./killSession.sh: /bin/bash: bad interpreter: Text file busy”错误提示,如下所示: [or ...

  4. eclipse的使用-------Text File Encoding没有GBK选项的设置

    eclipse的使用-------Text File Encoding没有GBK选项的设置 2013-12-25 09:48:06 标签:java myeclipse使用 有一个项目是使用GBK编码的 ...

  5. Writing Text File From A Tabular Block In Oracle Forms

    The example given below for writing text file or CSV using Text_IO package from a tabular block in O ...

  6. create feature from text file

    '''---------------------------------------------------------------------------------- Tool Name: Cre ...

  7. The 12th tip of DB Query Analyzer, powerful in text file process

    MA Gen feng ( Guangdong Unitoll Services incorporated, Guangzhou 510300) Abstract   It's very powerf ...

  8. 【转】shell脚本执行时报"bad interpreter: Text file busy"的解决方法

    1)问题现象: 在ubuntu下执行以下脚本( while_count),报错: -bash: ./while_count: /bin/bash: bad interpreter: Text file ...

  9. memtrack: Couldn't load memtrack module (No such file or directory) 的问题解决

    通过了编译,可是在模拟器运行时,却出现stopping…….查看logcat,发现出现错误: E/memtrack: Couldn't load memtrack module (No such fi ...

随机推荐

  1. 「Poj1845」Sumdiv 解题报告

    题面戳这里 啥都别看,只是求 \(a^b\)所有的因数的和 思路: 真没想到! 其实我们可以先将\(a^b\)分解成质因数的 因为\(a^b\)的因数肯定是\(a^b\)的质因数在一定的条件下相乘而成 ...

  2. Hello2020(前四题题解)

    Hello,2020!新的一年从快乐的掉分开始…… 我在m3.codeforces.com这个镜像网站中一开始还打不开D题,我…… 还有话说今天这场为什么那么多二分. 比赛传送门:https://co ...

  3. 常见的sql注入环境搭建

    常见的sql注入环境搭建 By : Mirror王宇阳 Time:2020-01-06 PHP+MySQL摘要 $conn = new mysqli('数据库服务器','username','pass ...

  4. JavaScript 继承小记

    面向对象编程很重要的一个方面,就是对象的继承.A 对象通过继承 B 对象,就能直接拥有 B 对象的所有属性和方法.这对于代码的复用是非常有用的. 大部分面向对象的编程语言,都是通过“类”(class) ...

  5. 彻底掌握CORS跨源资源共享

    本文来自于公众号链接: 彻底掌握CORS跨源资源共享 ) 本文接上篇公众号文章:彻底理解浏览器同源策略SOP 一.概述 在云时代,各种SAAS应用层出不穷,各种互联网API接口越来越丰富,H5技术在微 ...

  6. ATOM插件及快捷键

    xml-formatter :https://atom.io/packages/xml-formatter xml格式化工具 SHIFT-CTRL-X:快速格式化 SHIFT-CTRL-M:移除换行符 ...

  7. json中含有换行符'\r','\n'的处理

    一.josn简易说明  json是一种轻量级的数据交换格式,是一系列格式字符串.在数据交换中,经常会使用到,具有易读性,轻量级.很多地方会使用到,用处广泛.如下:(截取的一段json体) " ...

  8. 全流程开发 TP6.0实战高并发电商服务系统*完

    在TP6框架中我们可以学到TP整体知识,如下图一所示: 图一:TP6整体知识点 这些内容都会在实战课程中一一涵盖,并且在课程中我们会用到五层架构思想(如图二),和传统的MVC架构有所不一样,这样做可以 ...

  9. Windows10内嵌Ubuntu子系统配置python开发环境

    Windows10内嵌Ubuntu子系统配置python开发环境 安装pycharm. 到intellij idea网站下载Linux环境下载免费的pycharm,通过ubuntu子系统内部的/mnt ...

  10. GitHub高级搜索指南

    还在为自学时找不到适合练手的项目而苦恼? 还在好奇别人是如何在GitHub众多项目中找到高质量代码的? 真的是因为他们独具慧眼吗? 不,其实他们只是掌握了正确的搜索方法. 下面介绍几种常用的GitHu ...