Merge pull request #230 from jseabold/python-install
Make the Python wrappers installable without path munging
This commit is contained in:
commit
23c273173f
@ -1,5 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
import sys
|
||||
|
||||
def loadfmap( fname ):
|
||||
fmap = {}
|
||||
|
||||
@ -1,10 +1,6 @@
|
||||
#!/usr/bin/python
|
||||
import sys
|
||||
import numpy as np
|
||||
import scipy.sparse
|
||||
# append the path to xgboost, you may need to change the following line
|
||||
# alternatively, you can add the path to PYTHONPATH environment variable
|
||||
sys.path.append('../../wrapper')
|
||||
import xgboost as xgb
|
||||
|
||||
### simple example
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
#!/usr/bin/python
|
||||
import sys
|
||||
import numpy as np
|
||||
sys.path.append('../../wrapper')
|
||||
import xgboost as xgb
|
||||
|
||||
dtrain = xgb.DMatrix('../data/agaricus.txt.train')
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
#!/usr/bin/python
|
||||
import sys
|
||||
import numpy as np
|
||||
sys.path.append('../../wrapper')
|
||||
import xgboost as xgb
|
||||
|
||||
### load data in do training
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
#!/usr/bin/python
|
||||
import sys
|
||||
import numpy as np
|
||||
sys.path.append('../../wrapper')
|
||||
import xgboost as xgb
|
||||
###
|
||||
# advanced: cutomsized loss function
|
||||
|
||||
@ -1,6 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
import sys
|
||||
sys.path.append('../../wrapper')
|
||||
import xgboost as xgb
|
||||
##
|
||||
# this script demonstrate how to fit generalized linear model in xgboost
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
#!/usr/bin/python
|
||||
import sys
|
||||
import numpy as np
|
||||
sys.path.append('../../wrapper')
|
||||
import xgboost as xgb
|
||||
|
||||
### load data in do training
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
#!/usr/bin/python
|
||||
import sys
|
||||
import numpy as np
|
||||
sys.path.append('../../wrapper')
|
||||
import xgboost as xgb
|
||||
|
||||
### load data in do training
|
||||
|
||||
@ -4,8 +4,6 @@ Created on 1 Apr 2015
|
||||
@author: Jamie Hall
|
||||
'''
|
||||
|
||||
import sys
|
||||
sys.path.append('../../wrapper')
|
||||
import xgboost as xgb
|
||||
|
||||
import numpy as np
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
#!/usr/bin/python
|
||||
import sys
|
||||
import numpy as np
|
||||
sys.path.append('../../wrapper')
|
||||
import xgboost as xgb
|
||||
|
||||
### load data in do training
|
||||
|
||||
@ -1,14 +1,6 @@
|
||||
#!/usr/bin/python
|
||||
# this is the example script to use xgboost to train
|
||||
import inspect
|
||||
import os
|
||||
import sys
|
||||
import numpy as np
|
||||
# add path of xgboost python module
|
||||
code_path = os.path.join(
|
||||
os.path.split(inspect.getfile(inspect.currentframe()))[0], "../../wrapper")
|
||||
|
||||
sys.path.append(code_path)
|
||||
|
||||
import xgboost as xgb
|
||||
|
||||
|
||||
@ -1,9 +1,6 @@
|
||||
#!/usr/bin/python
|
||||
# make prediction
|
||||
import sys
|
||||
import numpy as np
|
||||
# add path of xgboost python module
|
||||
sys.path.append('../../wrapper/')
|
||||
import xgboost as xgb
|
||||
|
||||
# path to where the data lies
|
||||
|
||||
@ -1,9 +1,6 @@
|
||||
#!/usr/bin/python
|
||||
# this is the example script to use xgboost to train
|
||||
import sys
|
||||
import numpy as np
|
||||
# add path of xgboost python module
|
||||
sys.path.append('../../wrapper/')
|
||||
import xgboost as xgb
|
||||
from sklearn.ensemble import GradientBoostingClassifier
|
||||
import time
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
#! /usr/bin/python
|
||||
import sys
|
||||
import numpy as np
|
||||
sys.path.append('../../wrapper/')
|
||||
import xgboost as xgb
|
||||
|
||||
# label need to be 0 to num_class -1
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
import sys
|
||||
|
||||
fo = open( 'machine.txt', 'w' )
|
||||
cnt = 6
|
||||
|
||||
@ -10,13 +10,17 @@ This should give you xgboost.exe for CLI version and xgboost_wrapper.dll for pyt
|
||||
|
||||
Use Python Module
|
||||
=====
|
||||
* After you build the dll, you can simply add the path to [../wrapper](../wrapper) to sys.path and import xgboost
|
||||
* After you build the dll, you can install the Python package from the [../wrapper](../wrapper) folder
|
||||
|
||||
```
|
||||
python setup.py install
|
||||
```
|
||||
|
||||
And import it as usual
|
||||
|
||||
```
|
||||
sys.path.append('path/to/xgboost/wrapper')
|
||||
import xgboost as xgb
|
||||
```
|
||||
* Alternatively, you can add that path to system enviroment variable ```PYTHONPATH```
|
||||
- Doing so allows you to import xgboost directly like other python packages
|
||||
|
||||
R Package
|
||||
====
|
||||
|
||||
@ -5,6 +5,7 @@ This folder provides wrapper of xgboost to other languages
|
||||
Python
|
||||
=====
|
||||
* To make the python module, type ```make``` in the root directory of project
|
||||
* Install with `python setup.py install` from this directory.
|
||||
* Refer also to the walk through example in [demo folder](../demo/guide-python)
|
||||
|
||||
R
|
||||
|
||||
0
wrapper/__init__.py
Normal file
0
wrapper/__init__.py
Normal file
28
wrapper/setup.py
Normal file
28
wrapper/setup.py
Normal file
@ -0,0 +1,28 @@
|
||||
import os
|
||||
|
||||
from setuptools import setup
|
||||
|
||||
|
||||
class XGBoostLibraryNotFound(Exception):
|
||||
pass
|
||||
|
||||
|
||||
cur_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
if os.name == 'nt':
|
||||
dll_path = os.path.join(cur_dir,
|
||||
'../windows/x64/Release/xgboost_wrapper.dll')
|
||||
else:
|
||||
dll_path = os.path.join(cur_dir, 'libxgboostwrapper.so')
|
||||
|
||||
if not os.path.exists(dll_path):
|
||||
raise XGBoostLibraryNotFound("XGBoost library not found. Did you run "
|
||||
"../make?")
|
||||
|
||||
setup(name="xgboost",
|
||||
version="0.32",
|
||||
description="Python wrappers for XGBoost: eXtreme Gradient Boosting",
|
||||
zip_safe=False,
|
||||
py_modules=['xgboost'],
|
||||
data_files=[dll_path],
|
||||
url="https://github.com/dmlc/xgboost")
|
||||
Loading…
x
Reference in New Issue
Block a user