XGBoostror:不支持Unicode-3

发布于 2025-02-12 12:51:02 字数 1565 浏览 1 评论 0原文

我正在尝试从泡菜文件中的简化应用中加载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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小猫一只 2025-02-19 12:51:02

我遇到了一个类似的问题,带有相同的Xgboostror。在我的情况下,原因是dtype ndarray,应该是object

假设您的fart_listnumpy.ndarray,并且您以这样的方式创建它:

feat_list = np.array(features)

添加dtype = object

feat_list = np.array(features, dtype=object)

应该执行技巧。

I had a similar problem which came along with the the same XGBoostError. In my case the reason was the dtype of ndarray, which was supposed to be object.

Assuming that your feat_list is numpy.ndarray and that you create it in such way:

feat_list = np.array(features)

adding dtype=object:

feat_list = np.array(features, dtype=object)

should do the trick.

美人迟暮 2025-02-19 12:51:02

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文