XGBoostror:不支持Unicode-3
我正在尝试从泡菜文件中的简化应用中加载XGBClassifier。
当我加载它并尝试在新输入值上预测时,它会引发错误:
XGBoostError: [11:25:40] c:\users\administrator\workspace\xgboost-win64_release_1.6.0\src\data\array_interface.h:462: Unicode-3 is not supported.
整个追溯是:
2022-07-02 11:25:40.046 Uncaught app exception
Traceback (most recent call last):
File "C:\Users\\Anaconda3\lib\site-packages\streamlit\scriptrunner\script_runner.py", line 554, in _run_script
exec(code, module.__dict__)
File "temp.py", line 250, in <module>
st.write(clf.predict(feat_list))
File "C:\Users\\Anaconda3\lib\site-packages\xgboost\sklearn.py", line 1434, in predict
class_probs = super().predict(
File "C:\Users\\Anaconda3\lib\site-packages\xgboost\sklearn.py", line 1049, in predict
predts = self.get_booster().inplace_predict(
File "C:\Users\\Anaconda3\lib\site-packages\xgboost\core.py", line 2102, in inplace_predict
_check_call(
File "C:\Users\\Anaconda3\lib\site-packages\xgboost\core.py", line 203, in _check_call
raise XGBoostError(py_str(_LIB.XGBGetLastError()))
xgboost.core.XGBoostError: [11:25:40] c:\users\administrator\workspace\xgboost-win64_release_1.6.0\src\data\array_interface.h:462: Unicode-3
is not supported.
我以这种方式加载模型:
clf = pickle.load(open('xgb.pkl', "rb"))
或者
clf = xgboost.XGBClassifier(tree_method ="hist", enable_categorical=True)
clf.load_model("model.json")
我预测使用:
clf.predict(feat_list)
I am trying to load an XGBClassifier in my streamlit app from a pickle file.
When I load it and try to predict on the new input values, it throws the error:
XGBoostError: [11:25:40] c:\users\administrator\workspace\xgboost-win64_release_1.6.0\src\data\array_interface.h:462: Unicode-3 is not supported.
The entire traceback is:
2022-07-02 11:25:40.046 Uncaught app exception
Traceback (most recent call last):
File "C:\Users\\Anaconda3\lib\site-packages\streamlit\scriptrunner\script_runner.py", line 554, in _run_script
exec(code, module.__dict__)
File "temp.py", line 250, in <module>
st.write(clf.predict(feat_list))
File "C:\Users\\Anaconda3\lib\site-packages\xgboost\sklearn.py", line 1434, in predict
class_probs = super().predict(
File "C:\Users\\Anaconda3\lib\site-packages\xgboost\sklearn.py", line 1049, in predict
predts = self.get_booster().inplace_predict(
File "C:\Users\\Anaconda3\lib\site-packages\xgboost\core.py", line 2102, in inplace_predict
_check_call(
File "C:\Users\\Anaconda3\lib\site-packages\xgboost\core.py", line 203, in _check_call
raise XGBoostError(py_str(_LIB.XGBGetLastError()))
xgboost.core.XGBoostError: [11:25:40] c:\users\administrator\workspace\xgboost-win64_release_1.6.0\src\data\array_interface.h:462: Unicode-3
is not supported.
I load the model this way:
clf = pickle.load(open('xgb.pkl', "rb"))
Or
clf = xgboost.XGBClassifier(tree_method ="hist", enable_categorical=True)
clf.load_model("model.json")
And I predict using:
clf.predict(feat_list)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我遇到了一个类似的问题,带有相同的Xgboostror。在我的情况下,原因是
dtype
ndarray
,应该是object
。假设您的
fart_list
是numpy.ndarray
,并且您以这样的方式创建它:添加
dtype = object
:应该执行技巧。
I had a similar problem which came along with the the same XGBoostError. In my case the reason was the
dtype
ofndarray
, which was supposed to beobject
.Assuming that your
feat_list
isnumpy.ndarray
and that you create it in such way:adding
dtype=object
:should do the trick.
Encode text as UTF-8 with error handling but while you might run into string error as well since XGBoost requires the output variables to be numeric.因此,您可能还需要解决这个问题,并且使用咸菜文件记住加载模型和矢量器
Encode text as UTF-8 with error handling but while you might run into string error as well since XGBoost requires the output variables to be numeric. So you might need to address this as well and with the pickle file remember to load the model and the vectorizer too