From 8c28a209a95135f24148cd4105cd23c9e4991694 Mon Sep 17 00:00:00 2001 From: anystar Date: Wed, 25 Dec 2024 16:56:31 +0800 Subject: [PATCH] xgboost2sqlplus --- .DS_Store | Bin 0 -> 6148 bytes README.md | 424 +----------------- docs/conf.py | 6 +- tests/test_xgboost2sql.py | 2 +- xgboost2sql/__init__.py | 7 - xgboost2sqlplus/__init__.py | 7 + .../xgboost2sqlplus.py | 0 7 files changed, 20 insertions(+), 426 deletions(-) create mode 100644 .DS_Store delete mode 100644 xgboost2sql/__init__.py create mode 100644 xgboost2sqlplus/__init__.py rename xgboost2sql/xgboost2sql.py => xgboost2sqlplus/xgboost2sqlplus.py (100%) diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..7a37eb0105aa43ec3a9528e24f353a03cd499a2f GIT binary patch literal 6148 zcmeHK%TD7k6g_4-nm{DzayCf$f=I&`q@@8O@sKDi*fFK0LbQ}uCD>)pKky5D->imn zuPqe2upObnSMoiMbC2zNlGrf-)14200c`*Yi(qSo?j4i+QWk8nL!_=KPS!oxsiKU3vwa)o$&N22! zTp9->CLZG&kAA!;XI2}^t+01KLwZqw@tohl=g6!)&i6M?@a#dIy~va~jxpeSHPbOR z=x;Cy`sW+wv6#}AH164ANoq0rs6bR8D)6R&tPdHBVBxT~s7nW(9s!6gHmk8NKMTUi z92O31i@ZZKmP)i# > pipy包:https://pypi.org/project/xgboost2sql/ -本项目在xgboost2sql的基础上,对value is missing的情况进行fix,此外扩充了xgboost有类别(category)作为模型输入时的2sql处理 ## 环境准备 -可以不用单独创建虚拟环境,因为对包的依赖没有版本要求 +可以不用单独创建虚拟环境,因为对包的依赖没有版本要求。本项目在xgboost2sql的基础上,对value is missing的情况进行fix,此外扩充了xgboost有类别(category)作为模型输入时的2sql处理 ### `xgboost2sql` 安装 pip install(pip安装) @@ -31,14 +30,19 @@ Source code install(源码安装) python setup.py install ``` +添加代码相关内容 + +```bash +将xgboost2sql中的xgboost2sql.py中的内容替换为本项目中的xgboost2sqlplus.py中的所有内容 +``` + ## 运行样例 ###【注意:::核验对比python模型预测出来的结果和sql语句预测出来的结果是否一致请查看教程代码】tutorial_code.ipynb。代码位置:"https://github.com/ZhengRyan/xgboost2sql/tree/master/examples" + 导入相关依赖 ```python import xgboost as xgb -from sklearn.datasets import make_classification -from sklearn.model_selection import train_test_split + from xgboost2sql import XGBoost2Sql ``` @@ -75,414 +79,4 @@ xgb2sql.save() + 将sql语句打印出来 ```python print(sql_str) -``` - -```sql -select key,1 / (1 + exp(-(tree_1_score + tree_2_score + tree_3_score)+(-0.0))) as score - from ( - select key, - --tree1 - case when (f9<-1.64164519 or f9 is null) then - case when (f3<-4.19117069 or f3 is null) then - case when (f2<-1.31743848 or f2 is null) then - -0.150000006 - else - -0.544186056 - end - else - case when (f3<1.23432565 or f3 is null) then - case when (f7<-2.55682254 or f7 is null) then - -0.200000018 - else - case when (f5<0.154983491 or f5 is null) then - 0.544721723 - else - case when (f3<0.697217584 or f3 is null) then - -0.150000006 - else - 0.333333373 - end - end - end - else - case when (f5<-1.0218116 or f5 is null) then - case when (f0<-0.60882163 or f0 is null) then - case when (f2<0.26019755 or f2 is null) then - 0.0666666701 - else - -0.300000012 - end - else - -0.520000041 - end - else - 0.333333373 - end - end - end - else - case when (f9<1.60392439 or f9 is null) then - case when (f3<0.572542191 or f3 is null) then - case when (f5<0.653370142 or f5 is null) then - case when (f7<-0.765973091 or f7 is null) then - case when (f3<-0.432390809 or f3 is null) then - 0.204000011 - else - -0.485454559 - end - else - case when (f3<-1.20459461 or f3 is null) then - -0.5104478 - else - 0.441509455 - end - end - else - case when (f7<0.133017987 or f7 is null) then - case when (f8<0.320554674 or f8 is null) then - -0.290322572 - else - 0.368339777 - end - else - case when (f8<-0.211985052 or f8 is null) then - 0.504000008 - else - -0.525648415 - end - end - end - else - case when (f7<2.22314501 or f7 is null) then - case when (f8<-0.00532855326 or f8 is null) then - case when (f8<-0.204920739 or f8 is null) then - -0.533991575 - else - -0.200000018 - end - else - 0.428571463 - end - else - case when (f3<1.33772755 or f3 is null) then - case when (f0<-0.975171864 or f0 is null) then - 0.163636371 - else - 0.51818186 - end - else - -0 - end - end - end - else - case when (f3<1.77943277 or f3 is null) then - case when (f7<-0.469875157 or f7 is null) then - case when (f3<-0.536645889 or f3 is null) then - case when (f9<1.89841866 or f9 is null) then - -0 - else - 0.333333373 - end - else - case when (f4<-2.43660188 or f4 is null) then - 0.150000006 - else - 0.551020443 - end - end - else - case when (f1<-0.0788691565 or f1 is null) then - 0.150000006 - else - -0.375 - end - end - else - case when (f4<-1.73232496 or f4 is null) then - -0.150000006 - else - case when (f6<-1.6080606 or f6 is null) then - -0.150000006 - else - case when (f7<-0.259483218 or f7 is null) then - -0.558620751 - else - -0.300000012 - end - end - end - end - end - end - as tree_1_score, ---tree2 - case when (f9<-1.64164519 or f9 is null) then - case when (f3<-4.19117069 or f3 is null) then - case when (f0<0.942570388 or f0 is null) then - -0.432453066 - else - -0.128291652 - end - else - case when (f3<1.23432565 or f3 is null) then - case when (f7<-2.55682254 or f7 is null) then - -0.167702854 - else - case when (f5<0.154983491 or f5 is null) then - case when (f1<2.19985676 or f1 is null) then - 0.41752997 - else - 0.115944751 - end - else - 0.115584135 - end - end - else - case when (f5<-1.0218116 or f5 is null) then - case when (f0<-0.60882163 or f0 is null) then - -0.119530827 - else - -0.410788596 - end - else - 0.28256765 - end - end - end - else - case when (f9<1.60392439 or f9 is null) then - case when (f3<0.460727394 or f3 is null) then - case when (f5<0.653370142 or f5 is null) then - case when (f7<-0.933565617 or f7 is null) then - case when (f3<-0.572475374 or f3 is null) then - 0.182491601 - else - -0.377898693 - end - else - case when (f3<-1.20459461 or f3 is null) then - -0.392539263 - else - 0.352721155 - end - end - else - case when (f7<0.207098693 or f7 is null) then - case when (f8<0.498489976 or f8 is null) then - -0.193351224 - else - 0.29298231 - end - else - case when (f8<-0.117464997 or f8 is null) then - 0.400667101 - else - -0.402199954 - end - end - end - else - case when (f7<1.98268723 or f7 is null) then - case when (f8<-0.00532855326 or f8 is null) then - case when (f7<1.36281848 or f7 is null) then - -0.408002198 - else - -0.236123681 - end - else - case when (f5<1.14038813 or f5 is null) then - 0.404326111 - else - -0.110877581 - end - end - else - case when (f3<1.56952488 or f3 is null) then - case when (f5<2.14646816 or f5 is null) then - 0.409404457 - else - 0.0696995854 - end - else - -0.32059738 - end - end - end - else - case when (f3<1.77943277 or f3 is null) then - case when (f7<-0.469875157 or f7 is null) then - case when (f3<-0.536645889 or f3 is null) then - case when (f9<1.89841866 or f9 is null) then - -0 - else - 0.28256765 - end - else - 0.419863999 - end - else - case when (f3<0.444227457 or f3 is null) then - -0.34664312 - else - 0.0693304539 - end - end - else - case when (f4<-1.10089087 or f4 is null) then - case when (f3<2.3550868 or f3 is null) then - 0.0147894565 - else - -0.331404865 - end - else - -0.421277165 - end - end - end - end - as tree_2_score, ---tree3 - case when (f9<-1.64164519 or f9 is null) then - case when (f3<-4.19117069 or f3 is null) then - case when (f4<-1.30126143 or f4 is null) then - -0.0772174299 - else - -0.374165356 - end - else - case when (f3<1.23432565 or f3 is null) then - case when (f7<-2.55682254 or f7 is null) then - -0.142005175 - else - case when (f5<0.154983491 or f5 is null) then - case when (f7<3.59379435 or f7 is null) then - 0.352122813 - else - 0.132789165 - end - else - 0.0924336985 - end - end - else - case when (f5<-1.0218116 or f5 is null) then - case when (f0<-0.60882163 or f0 is null) then - -0.0954768136 - else - -0.351594836 - end - else - 0.245992288 - end - end - end - else - case when (f9<1.60392439 or f9 is null) then - case when (f3<0.347133756 or f3 is null) then - case when (f5<0.661561131 or f5 is null) then - case when (f7<-0.933565617 or f7 is null) then - case when (f3<-0.472413659 or f3 is null) then - 0.116336405 - else - -0.313245147 - end - else - case when (f3<-1.5402329 or f3 is null) then - -0.352897167 - else - 0.311400592 - end - end - else - case when (f7<0.275665522 or f7 is null) then - case when (f8<0.403402805 or f8 is null) then - -0.292606086 - else - 0.220064178 - end - else - case when (f8<-0.0442957953 or f8 is null) then - 0.350784421 - else - -0.336107522 - end - end - end - else - case when (f7<1.77503061 or f7 is null) then - case when (f8<0.196157426 or f8 is null) then - case when (f7<1.36281848 or f7 is null) then - -0.3376683 - else - -0.0711223111 - end - else - case when (f7<-0.661211252 or f7 is null) then - 0.434363276 - else - -0.219307661 - end - end - else - case when (f3<1.37940335 or f3 is null) then - case when (f6<1.34894884 or f6 is null) then - 0.367155522 - else - 0.124757253 - end - else - -0.293739736 - end - end - end - else - case when (f3<1.77943277 or f3 is null) then - case when (f7<-0.469875157 or f7 is null) then - case when (f3<-0.536645889 or f3 is null) then - case when (f9<1.89841866 or f9 is null) then - -0 - else - 0.245992288 - end - else - case when (f0<1.60565615 or f0 is null) then - 0.357973605 - else - 0.193993196 - end - end - else - case when (f9<1.89456153 or f9 is null) then - -0.276471078 - else - 0.111896731 - end - end - else - case when (f1<1.35706067 or f1 is null) then - case when (f4<-1.10089087 or f4 is null) then - case when (f3<2.3550868 or f3 is null) then - 0.0119848112 - else - -0.284813672 - end - else - -0.376859784 - end - else - case when (f2<-0.25748384 or f2 is null) then - 0.0723158419 - else - -0.253415495 - end - end - end - end - end - as tree_3_score - from data_table) -``` - - +``` \ No newline at end of file diff --git a/docs/conf.py b/docs/conf.py index 29c03e4..946d7f4 100755 --- a/docs/conf.py +++ b/docs/conf.py @@ -21,7 +21,7 @@ import sys sys.path.insert(0, os.path.abspath('..')) -import xgboost2sql +import xgboost2sqlplus # -- General configuration --------------------------------------------- @@ -55,9 +55,9 @@ # the built documents. # # The short X.Y version. -version = xgboost2sql.__version__ +version = xgboost2sqlplus.__version__ # The full version, including alpha/beta/rc tags. -release = xgboost2sql.__version__ +release = xgboost2sqlplus.__version__ # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/tests/test_xgboost2sql.py b/tests/test_xgboost2sql.py index e1a6dd3..f8a64e0 100644 --- a/tests/test_xgboost2sql.py +++ b/tests/test_xgboost2sql.py @@ -6,7 +6,7 @@ from sklearn.datasets import make_classification from sklearn.model_selection import train_test_split -from xgboost2sql import XGBoost2Sql +from xgboost2sqlplus import XGBoost2Sql X, y = make_classification(n_samples=10000, n_features=10, diff --git a/xgboost2sql/__init__.py b/xgboost2sql/__init__.py deleted file mode 100644 index fb496e3..0000000 --- a/xgboost2sql/__init__.py +++ /dev/null @@ -1,7 +0,0 @@ -"""Top-level package for xgboost2sql.""" - -__author__ = """RyanZheng""" -__email__ = 'zhengruiping000@163.com' -__version__ = '0.1.0' - -from .xgboost2sql import XGBoost2Sql diff --git a/xgboost2sqlplus/__init__.py b/xgboost2sqlplus/__init__.py new file mode 100644 index 0000000..de1e566 --- /dev/null +++ b/xgboost2sqlplus/__init__.py @@ -0,0 +1,7 @@ +"""Top-level package for xgboost2sqlplus.""" + +__author__ = """huangqinglong""" +__email__ = '757451920@qq.com' +__version__ = '0.1.0' + +from .xgboost2sqlplus import XGBoost2Sql diff --git a/xgboost2sql/xgboost2sql.py b/xgboost2sqlplus/xgboost2sqlplus.py similarity index 100% rename from xgboost2sql/xgboost2sql.py rename to xgboost2sqlplus/xgboost2sqlplus.py