如何在pyspark中加载xgboost模型?

dddzy1tm  于 2021-07-13  发布在  Spark
关注(0)|答案(0)|浏览(586)

我在用 xgboost4j-0.90 在Pypark。我有一个模型,我用交叉验证,我想知道什么是正确的方式加载后,它已经保存回来。
我是这样保存的:

import sys
from sparkxgb import XGBoostClassificationModel
path = 'models_prod'
os.mkdir(path)
cvModel.bestModel.save(os.path.join(sys.argv[1], 'model_prod_{}.model'.format(datetime.now().strftime('%Y-%m-%d'))))

但是当我试着把它装回去的时候。。。

from datetime import datetime
XGBoostClassificationModel.load(os.path.join(sys.argv[1], 'model_prod_{}.model'.format(datetime.now().strftime('%Y-%m-%d'))))

我得到这个错误:

TypeErrorTraceback (most recent call last)
<ipython-input-76-9c37de36b710> in <module>()
----> 1 sparkxgb.XGBoostClassificationModel.load(os.path.join(sys.argv[1], 'model_prod_{}.model'.format(datetime.now().strftime('%Y-%m-%d'))))

/opt/cloudera/parcels/CDH-6.3.4-1.cdh6.3.4.p0.6626826/lib/spark/python/pyspark/ml/util.py in load(cls, path)
    360     def load(cls, path):
    361         """Reads an ML instance from the input path, a shortcut of `read().load(path)`."""
--> 362         return cls.read().load(path)
    363 
    364 

/tmp/spark-ddebc1de-ff0b-4a61-9015-9eed1d020da0/userFiles-e8428975-a085-42ff-ae70-b92e722822ac/sparkxgb.zip/sparkxgb/util.py in read(cls)
     26     def read(cls):
     27         """Returns an XGBoostReader instance for this class."""
---> 28         return XGBoostReader(cls)
     29 
     30 

/tmp/spark-ddebc1de-ff0b-4a61-9015-9eed1d020da0/userFiles-e8428975-a085-42ff-ae70-b92e722822ac/sparkxgb.zip/sparkxgb/util.py in __init__(self, clazz)
     36     def __init__(self, clazz):
     37         self._clazz = clazz
---> 38         self._jread = self._load_java_obj(clazz).read()
     39 
     40     @classmethod

TypeError: 'JavaPackage' object is not callable

有人能告诉我怎么修这个吗?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题