【问题标题】:AttributeError: 'module' object has no attribute 'DMatrixAttributeError:“模块”对象没有属性“DMatrix”
【发布时间】:2017-10-04 14:16:59
【问题描述】:

我尝试了所有可能的解决方案,但仍然出现此错误,已经安装了所有依赖库。

import numpy as np
import pandas as pd

from sklearn.model_selection import train_test_split
from sklearn.preprocessing import LabelEncoder

from tqdm import tqdm
import xgboost as xgb

d_train = xgb.DMatrix(X_train, label=y_train)
AttributeError: 'module' object has no attribute 'DMatrix'

【问题讨论】:

  • xgboost 未正确导入。如果您在同一目录中有 xgboost.py 文件,请尝试重命名它。
  • 已经尝试过但仍然出现错误。
  • 您是否尝试使用pip 卸载并重新安装xgboost?还有你的xgboost是什么版本的?
  • 我在重新安装 xgboost 时解决了这个问题,谢谢
  • 我遇到了同样的问题。我也可以通过简单地重新安装 xgboost 来解决这个问题。

标签: python python-2.7 machine-learning xgboost


【解决方案1】:

您可以使用以下命令强制升级 XGBoost:

python -m pip install xgboost --user --upgrade pip

这为我解决了问题。

【讨论】:

    猜你喜欢
    • 2016-07-04
    • 2010-11-18
    相关资源
    最近更新 更多