XGBoostをOptunaでtrain実行後、新しい単体データにOptunaのベストパラメータを適応させ予測しようとすると
py
1Typeerror: nosupportde conversion for types: (dtype('O'),) 2TypeError can not initialize DMatrix from DMatrix
と出てしまい、先に進めません。
先にエラーを書いておきます。
######エラー
・predictのところで以下のエラーが出ます。以下エラー表示
py
1Traceback (most recent call last): 2 File "/myDirXXX/xgboost/python-package/xgboost/core.py", line 412, in __init__ 3 csr = scipy.sparse.csr_matrix(data) 4 File "/usr/local/lib/python3.5/dist-packages/scipy/sparse/compressed.py", line 79, in __init__ 5 self._set_self(self.__class__(coo_matrix(arg1, dtype=dtype))) 6 File "/usr/local/lib/python3.5/dist-packages/scipy/sparse/compressed.py", line 32, in __init__ 7 arg1 = arg1.asformat(self.format) 8 File "/usr/local/lib/python3.5/dist-packages/scipy/sparse/base.py", line 326, in asformat 9 return convert_method(copy=copy) 10 File "/usr/local/lib/python3.5/dist-packages/scipy/sparse/coo.py", line 393, in tocsr 11 data = np.empty_like(self.data, dtype=upcast(self.dtype)) 12 File "/usr/local/lib/python3.5/dist-packages/scipy/sparse/sputils.py", line 52, in upcast 13 raise TypeError('no supported conversion for types: %r' % (args,)) 14TypeError: no supported conversion for types: (dtype('O'),) 15 16During handling of the above exception, another exception occurred: 17 18Traceback (most recent call last): 19 File "/myDirXXX/cam/20190407XGBoostOptuna/4.py", line 383, in <module> 20 XXXX=modelXGBparam.predict(dataMatrixNew) 21 File "/myDirXXX/xgboost/python-package/xgboost/sklearn.py", line 766, in predict 22 test_dmatrix = DMatrix(data, missing=self.missing, nthread=self.n_jobs) 23 File "/myDirXXX/xgboost/python-package/xgboost/core.py", line 416, in __init__ 24 ' {}'.format(type(data).__name__)) 25TypeError: can not initialize DMatrix from DMatrix 26
以上エラー表示
以下、該当箇所の抜き出しです。
py
1 2#ここまでで学習済み 3#新規データ取得 4#このデータには最後の列にフラグを付けてありませんので、Train時より1列少ないです。 5listDataStraight = np.reshape(listDataStraight,[1,-1])#サイズ整え 6listDataStraight = std_scl.transform(listDataStraight)#正規化 ndarray 7 8#データをXGB専用形式に整える 9dataMatrixNew = xgb.DMatrix(listDataStraight) 10 11#パラメーターを整える 12optp = optuna.study.load_study() 13modelXGBparam = xgb.XGBClassifier(optp) 14 15#最終判断 ここでエラーが起きます 16XXXX=modelXGBparam.predict(dataMatrixNew) 17 18Print(XXXX)#ここまでたどり着かない。 19 20
補足情報
似たようなやり取りを一つだけ見つけたのですが、今ひとつ理解できません。
https://stackoverflow.com/questions/53506997/exception-during-xgboost-prediction-can-not-initialize-dmatrix-from-dmatrix?rq=1
python3.5
XGBoost0.82
主題以外の部分を削除しました。ご存知の方ご教示お願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。