找不到xgboost。尝试将XGBoost模型转换为核心ML模型时,XGBoost转换API是禁用的错误

发布于 2025-02-12 12:34:14 字数 2087 浏览 1 评论 0原文

我正在尝试将XGBoost模型转换为核心ML模型,我正在使用 Google Colab ,这是我的代码:

import pandas as pd
from sklearn.model_selection import train_test_split
import xgboost as xgb
import coremltools as ct


data = pd.read_csv('/content/Rugby Position Requirements Updated - Rugby Position Requirements.csv')

from sklearn.preprocessing import LabelEncoder
label_encoder = LabelEncoder()

data_copy = data.copy()

data_copy['Position_Numerical'] = label_encoder.fit_transform(data['Position'])
data = data_copy
data
features = ['Weight_KG', 'Height_CM', 'EBF', 'L_Run_S', '40m_Sprint_S', 'Speed_KMPH', 'Endurance', '1RM_Bench_Press_KG', 'Vertical_Jump_CM']
X = data[features].values

y = data.Position_Numerical

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.1, random_state = 11)

train = xgb.DMatrix(X_train, label = y_train)
test = xgb.DMatrix(X_test, label = y_test)

param = {
    'max_depth': 4,
    'eta': 0.3,
    'objective': 'multi:softmax',
    'num_class': 15 }
epochs = 10

xgb_model = xgb.train(param, train, epochs)

coreml_model = ct.converters.xgboost.convert(xgb_model)
coreml_model.save('my_model.mlmodel')

这是我遇到的整个错误:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-61-d5b7e2c517d7> in <module>()
      1 import coremltools as ct
      2 
----> 3 coreml_model = ct.converters.xgboost.convert(xgb_model)
      4 

1 frames
/usr/local/lib/python3.7/dist-packages/coremltools/converters/xgboost/_tree_ensemble.py in convert_tree_ensemble(model, feature_names, target, force_32bit_float, mode, class_labels, n_classes)
    151     """
    152     if not (_HAS_XGBOOST):
--> 153         raise RuntimeError("xgboost not found. xgboost conversion API is disabled.")
    154     accepted_modes = ["regressor", "classifier"]
    155     if mode not in accepted_modes:

RuntimeError: xgboost not found. xgboost conversion API is disabled.

我尝试寻找修复没有运气。如何解决此问题?

I'm trying to convert an XGBoost model to a Core ML model, I'm using Google Colab and here's my code:

import pandas as pd
from sklearn.model_selection import train_test_split
import xgboost as xgb
import coremltools as ct


data = pd.read_csv('/content/Rugby Position Requirements Updated - Rugby Position Requirements.csv')

from sklearn.preprocessing import LabelEncoder
label_encoder = LabelEncoder()

data_copy = data.copy()

data_copy['Position_Numerical'] = label_encoder.fit_transform(data['Position'])
data = data_copy
data
features = ['Weight_KG', 'Height_CM', 'EBF', 'L_Run_S', '40m_Sprint_S', 'Speed_KMPH', 'Endurance', '1RM_Bench_Press_KG', 'Vertical_Jump_CM']
X = data[features].values

y = data.Position_Numerical

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.1, random_state = 11)

train = xgb.DMatrix(X_train, label = y_train)
test = xgb.DMatrix(X_test, label = y_test)

param = {
    'max_depth': 4,
    'eta': 0.3,
    'objective': 'multi:softmax',
    'num_class': 15 }
epochs = 10

xgb_model = xgb.train(param, train, epochs)

coreml_model = ct.converters.xgboost.convert(xgb_model)
coreml_model.save('my_model.mlmodel')

This is the whole error I'm getting:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-61-d5b7e2c517d7> in <module>()
      1 import coremltools as ct
      2 
----> 3 coreml_model = ct.converters.xgboost.convert(xgb_model)
      4 

1 frames
/usr/local/lib/python3.7/dist-packages/coremltools/converters/xgboost/_tree_ensemble.py in convert_tree_ensemble(model, feature_names, target, force_32bit_float, mode, class_labels, n_classes)
    151     """
    152     if not (_HAS_XGBOOST):
--> 153         raise RuntimeError("xgboost not found. xgboost conversion API is disabled.")
    154     accepted_modes = ["regressor", "classifier"]
    155     if mode not in accepted_modes:

RuntimeError: xgboost not found. xgboost conversion API is disabled.

I tried looking for a fix but no luck. How can I fix this issue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文