简体   繁体   中英

serialize adaboost classifier scikit-learn

I'm trying to use scikit-learn AdaBoostClassifier, and i'm trying to serialize the output classifier using cPickle to save it to database or a file, but i got out of memory error, and when i used marshal, it gave me the unmarshable object. So, i'm wondering how i can serialize this learned classifier.

def adboost_classify(X,Y):
   bdt = AdaBoostClassifier(DecisionTreeClassifier(max_depth=10),
                    algorithm="SAMME.R",
                     n_estimators=3000)
   t0 = time()
   bdt.fit(X, Y)
   t1 = time()
   thebytes = cPickle.dumps(bdt)

thank you in advance

This is because you attempt to store the whole representation in memory. Try writing it to a file directly instead:

with open('adaboostpickled.tmp', 'w') as output:
    cPikle.dump(bdt, output)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM