XGBOOST-DMATRIX [英] XGBOOST - DMATRIX

查看:987
本文介绍了XGBOOST-DMATRIX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我提取了一些在kaggle(linux)上运行的ML代码,并试图在Windows计算机上的jupyter笔记本中运行它.这是代码(其中一些):

I pulled some ML code that ran on kaggle (linux) and tried to run it in a jupyter notebook on a windows machine. Here is the code (some of it):

##### RUN XGBOOST
import xgboost as xgb

print("\nSetting up data for XGBoost ...")
# xgboost params
xgb_params = {
    'eta': 0.037,
    'max_depth': 5,
    'subsample': 0.80,
    'objective': 'reg:linear',
    'eval_metric': 'mae',
    'lambda': 0.8,   
    'alpha': 0.4, 
    'base_score': y_mean,
    'silent': 1
}

#### These lines were causing the folloing error on 9/1/2017:
# AttributeError: module 'xgboost' has no attribute 'DMatrix'
dtrain = xgb.DMatrix(x_train.values, y_train.values)
dtest = xgb.DMatrix(x_test)

num_boost_rounds = 250
print("num_boost_rounds="+str(num_boost_rounds))

# train model
print( "\nTraining XGBoost ...")
model = xgb.train(dict(xgb_params, silent=1), dtrain, 
num_boost_round=num_boost_rounds)

print( "\nPredicting with XGBoost ...")
xgb_pred1 = model.predict(dtest)

print( "\nFirst XGBoost predictions:" )
print(pd.DataFrame(xgb_pred1).head())

收到以下错误:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-7-a63b74bc35c6> in <module>()
     17 #### These lines were causing the folloing error on 9/1/2017:
     18 # AttributeError: module 'xgboost' has no attribute 'DMatrix'
---> 19 dtrain = xgb.DMatrix(x_train.values, y_train.values)
     20 dtest = xgb.DMatrix(x_test)
     21 

AttributeError: module 'xgboost' has no attribute 'DMatrix'

这很奇怪,因为我一直将xgboost模型从linux机器拉到Windows.我找不到有关如何修复Internet的任何信息,所以我想知道是否有人知道如何修复?

This is odd because I pull xgboost models from linux machines to windows all the time. I can not find any info on how to fix on the internet, so I am wondering if anyone knows how to fix?

推荐答案

我们可能有相同的问题.

We probably have the same problem.

我通过明确告诉Python在哪里找到xgboost库来解决它.

I solved it by telling Python explicitly where to find xgboost library.

原因是我有多个脚本,名称为xgboost.py. Python可能错误地导入了其中一个,因此找不到'DMatrix'的定义.

The reason is that I have more than one scripts with the name xgboost.py. Python might have imported one of them mistakenly, so that it cannot find the definition of 'DMatrix'.

这是我使用的命令:

export PYTHONPATH=~/xgboost/python-package

您应将〜/xgboost/python-package"更改为/xgboost/python-package/setup.py文件所在的文件夹.

You should change '~/xgboost/python-package' into the folder where your /xgboost/python-package/setup.py file located.

这篇关于XGBOOST-DMATRIX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆