Ami*_*mit 4 python regression machine-learning spyder xgboost
我正在尝试使用spyder和python运行xgboost,但我不断收到此错误:
\n\nAttributeError: 模块 \xe2\x80\x98xgboost\xe2\x80\x99 没有属性 \xe2\x80\x98XGBRegressor\xe2\x80\x99
\n\n这是代码:
\n\nimport xgboost as xgb \n\nxgb.XGBRegressor(max_depth=3, learning_rate=0.1, n_estimators=100, silent=True, \n objective=\'reg:linear\', gamma=0, min_child_weight=1, \n max_delta_step=0, subsample=1, colsample_bytree=1, \n seed=0, missing=None)\nRun Code Online (Sandbox Code Playgroud)\n\n错误是
\n\nTraceback (most recent call last):\n\n File "<ipython-input-33-d257a9a2a5d8>", line 1, in <module>\n xgb.XGBRegressor(max_depth=3, learning_rate=0.1, n_estimators=100, silent=True,\n\nAttributeError: module \'xgboost\' has no attribute \'XGBRegressor\'\nRun Code Online (Sandbox Code Playgroud)\n\n我有\nPython 3.5.2 :: Anaconda 4.2.0 (x86_64)
\n\n我该如何解决这个问题?
\n我们可能有同样的问题。
我通过明确告诉 Python 在哪里可以找到 xgboost 库来解决这个问题。
原因是我有多个名为 xgboost.py 的脚本。Python 可能错误地导入了其中之一,因此无法找到“XGBRegressor”的定义。
这是我使用的命令:
export PYTHONPATH=PATH_TO_YOUR_setup.py_file
Run Code Online (Sandbox Code Playgroud)
对我来说, PATH_TO_YOUR_setup.py_file 是 ~/xgboost/python-package