Comments (16)
can u provide a code producing the error?
from xgboost.
#!/usr/bin/python2
import sys
import pandas as pd
sys.path.append('/home/postgres/research/ktools/xgboost/python/')
import xgboost as xgb
""" here is an example of how to use converters """
data = pd.read_csv('data/training.csv',converters={32: lambda x:int(x=='s'.encode('utf-8')) })
print 'parse training dataset, shape=', data.shape
weight = data['Weight'].as_matrix()
train_Y = data['Label'].as_matrix()
train_X = data.ix[:,1:31].as_matrix()
""" parse test data """
data = pd.read_csv('data/test.csv')
test_X = data.ix[:,1:31].as_matrix()
idx = data.ix[:,0].as_matrix()
print 'parse test dataset, shape=', test_X.shape
#
test_size = 550000
weight = weight * float(test_size) / len(train_Y)
sum_wpos = sum( weight[i] for i in range(len(train_Y)) if train_Y[i] == 1.0 )
sum_wneg = sum( weight[i] for i in range(len(train_Y)) if train_Y[i] == 0.0 )
# print weight statistics
print ('weight statistics: wpos=%g, wneg=%g, ratio=%g' % ( sum_wpos, sum_wneg, sum_wneg/sum_wpos ))
# construct xgboost.DMatrix from numpy array, treat -999.0 as missing value
xgmat = xgb.DMatrix( train_X, label=train_Y, missing = -999.0, weight=weight )
xgmat_test = xgb.DMatrix( test_X, missing = -999.0 )
watchlist = [ (xgmat,'train') ]
# setup parameters for xgboost
param = {}
# use logistic regression loss, use raw prediction before logistic transformation
# since we only need the rank
param['objective'] = 'binary:logitraw'
# scale weight of positive examples
param['scale_pos_weight'] = sum_wneg/sum_wpos
param['bst:eta'] = 0.1
param['bst:max_depth'] = 6
param['eval_metric'] = 'auc'
param['silent'] = 1
param['nthread'] = 16
# you can directly throw param in, though we want to watch multiple metrics here
plst = list(param.items())+[('eval_metric', '[email protected]')]
# boost 120 tres
num_round = 20
print ('loading data end, start to boost trees')
bst = xgb.train( plst, xgmat, num_round, watchlist );
bst.save_model('higgs.model')
print ('finish training')
threshold_ratio = 0.15
outfile = 'higgs.pred.csv'
ypred = bst.predict( xgmat_test )
res = [ ( int(idx[i]), ypred[i] ) for i in range(len(ypred)) ]
rorder = {}
for k, v in sorted( res, key = lambda x:-x[1] ):
rorder[ k ] = len(rorder) + 1
# write out predictions
ntop = int( threshold_ratio * len(rorder ) )
fo = open(outfile, 'w')
nhit = 0
ntot = 0
fo.write('EventId,RankOrder,Class\n')
for k, v in res:
if rorder[k] <= ntop:
lb = 's'
nhit += 1
else:
lb = 'b'
# change output rank order to follow Kaggle convention
fo.write('%s,%d,%s\n' % ( k, len(rorder)+1-rorder[k], lb ) )
ntot += 1
fo.close()
print ('finished writing into prediction file')
from xgboost.
it's your startup code using pandas IO, running in spyder-2.3.0 (maybe it is a spyder related issue?)
with
- numpy-1.8.1
- pandas-0.14.1
- python-2.7.8
from xgboost.
Is it possible to simplify this code that produces the error? I would run for 1 round, and delete the write csv code. The error seems to occur in destructor of Booster, see.
https://github.com/tqchen/xgboost/blob/master/wrapper/xgboost.py#L79
My suspect is that somehow your run makes xgblib become None? If you can help to take a look what happened in the destructor, it would also be great
from xgboost.
I tried to run on my own machine, seems no such error occurs. I am using the most recent code from master, where python folder is renamed to wrapper
from xgboost.
OK, I suspect that this is due to the destructing order of python during exit. Maybe xglib in xgboost.py get destroyed before the destructor of DMatrix is called, and thus the error occurs, to validate if this is the cause of the problem, you can validate by print the xglib variable in destructor https://github.com/tqchen/xgboost/blob/master/wrapper/xgboost.py#L79
from xgboost.
Hi,
I add print xglib in L79 of wrapper/xgboost.py
# destructor
def __del__(self):
print xglib
xglib.XGDMatrixFree(self.handle)
the error messages are
None
Exception AttributeError: "'NoneType' object has no attribute 'XGDMatrixFree'" in <bound method DMatrix.__del__ of <xgboost.DMatrix instance at 0x7f711be1b7e8>> ignored
Exception AttributeError: "'NoneType' object has no attribute 'XGDMatrixFree'" in <bound method DMatrix.__del__ of <xgboost.DMatrix instance at 0x7f711be1f440>> ignored
...
None
loading data end, start to boost trees
finish training
finished writing into prediction file
[19] train-auc:0.929520 [email protected]:4.643400
Exception AttributeError: "'NoneType' object has no attribute 'XGBoosterFree'" in <bound method Booster.__del__ of <xgboost.Booster instance at 0x7f711be1b248>> ignored
from xgboost.
Seems this is indeed the problem I guessed. xgblib becomes None during Free ....
from xgboost.
Here is a possible fix. Add self.xglib = xglib in all the init function.
And call self.xglib.XGFree in all the dels.
On Monday, August 25, 2014, Liu Benyuan [email protected] wrote:
Hi,
I add print xglib in L79 of wrapper/xgboost.py
# destructor def __del__(self): print xglib xglib.XGDMatrixFree(self.handle)
the error messages are
None
Exception AttributeError: "'NoneType' object has no attribute 'XGDMatrixFree'" in <bound method DMatrix.del of <xgboost.DMatrix instance at 0x7f711be1b7e8>> ignored
Exception AttributeError: "'NoneType' object has no attribute 'XGDMatrixFree'" in <bound method DMatrix.del of <xgboost.DMatrix instance at 0x7f711be1f440>> ignored...
None
loading data end, start to boost trees
finish training
finished writing into prediction file
[19] train-auc:0.929520 [email protected]:4.643400
Exception AttributeError: "'NoneType' object has no attribute 'XGBoosterFree'" in <bound method Booster.del of <xgboost.Booster instance at 0x7f711be1b248>> ignored—
Reply to this email directly or view it on GitHub
https://github.com/tqchen/xgboost/issues/40#issuecomment-53365576.
Sincerely,
Tianqi Chen
Computer Science & Engineering, University of Washington
from xgboost.
Can you try this fix?
Change the destructor to
def __del__(self):
self.xglib.XGDMatrixFree(self.handle)
and in init https://github.com/tqchen/xgboost/blob/master/wrapper/xgboost.py#L41, add
def __init__(self, ...):
self.xglib = xglib
from xgboost.
This error still exists.
<CDLL '/home/postgres/research/ktools/xgboost/wrapper/libxgboostwrapper.so', handle 227b3a0 at 7fe640fbf2d0>
<CDLL '/home/postgres/research/ktools/xgboost/wrapper/libxgboostwrapper.so', handle 227b3a0 at 7fe640fbf2d0>
Exception AttributeError: "'NoneType' object has no attribute 'XGBoosterFree'" in <bound method Booster.__del__ of <xgboost.Booster instance at 0x7fe640e8cdd0>> ignored
where I print self.xglib
from xgboost.
However this warning can be safely ignored ?
from xgboost.
Can you make sure you called self.xglib.XGBoosterFree instead of xglib.XGBoosterFree ?
Since from the printed message, self.xglib is not NoneType, and the error is still because the handle is NoneType
This means the destructor is not called, and the memory might not be freed. But it won't affect the performance of your code.
from xgboost.
yes, I confirmed that by adding:
def __del__(self):
print self.xglib
print 'called __del__'
self.xglib.XGDMatrixFree(self.handle)
However I think the error is related to spyder, but not your code. Open ipython2
and run higgs-play_36.py
twice, and the messages will pump out without error.
<CDLL '/home/postgres/research/ktools/xgboost/wrapper/libxgboostwrapper.so', handle 1108d60 at 7f3caa42fc10>
called __del__
<CDLL '/home/postgres/research/ktools/xgboost/wrapper/libxgboostwrapper.so', handle 1108d60 at 7f3caa42fc10>
called __del__
from xgboost.
Thanks for clarifying the things!
from xgboost.
Still exists in LTR, only when I use set_group and pass a list
from xgboost.
Related Issues (20)
- Horizontal Federated Learning with Secure Features RFC
- [bug] Python - Cuda error (without using Cuda) HOT 5
- Pandas 2.2: Index.format is deprecated
- ArrayInterface handler for cuDF DataFrame cannot yet handle Boolean columns HOT 1
- src/metric/auc.cc:322: Check failed: auc <= local_area HOT 1
- XGBoost4j-spark CrossValidation train FAILED on multi-GPU environment: : Multiple processes running on same CUDA device is not supported! HOT 1
- [jvm-packages] Scaladoc is not working in latest XGBoost
- [CI] Tracker for improving build and CI/CD infrastructure
- [CI] Set up a nightly pipeline to test with dev versions of RAPIDS
- xgboost predict takes a long time
- xgboost4j_2.12:1.7.6 's (ml/dmlc/xgboost4j/java/XGBoostJNI.XGBoosterPredict) much slower than 0.90 in some model HOT 6
- NumPy 2.0 support HOT 2
- Tutorial on c-api distributed training of xgboost HOT 2
- Python 3.12 `xgboost.core.XGBoostError: Invalid Parameter format for nthread expect int but value='-1'` when `DMatrix` used with `import googlecloudprofiler`. HOT 6
- [CI] Retire Mac Mini worker in BuildKite
- [RFC] New logo for XGBoost HOT 1
- c-ares and BoringSSL version in xgboost 2.0.3 HOT 6
- Federated horizontal result does not align with basic training without federation
- monotone_constraints not working with xgb.regressor (python)
- xgboost 2.0.1 is breaking on rootless docker. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xgboost.