python - 属性错误: Module "lightgbm" has no attribute "LGBMClassifier" and "Dataset"

标签 python python-3.x lightgbm

我使用pip版本16.0.0安装了lightgbm(2.2.3),但在上传数据集时出错。代码如下:

import lightgbm as gbm 

d_train=gbm.Dataset(train_x,label=train_y)

File "lightgbm.py", line 13, in
import lightgbm as gbm
File "S:\MP pillai meet\Minor Project\ml-challenge-6-v1\ml-challenge-6\lightgbm.py", line 104, in d_train=gbm.Dataset(train_x,label=train_y)
AttributeError: module 'lightgbm' has no attribute 'Dataset'

最佳答案

我认为属性Attribute Error in Python有这个错误,参见:

Python 中的属性表示与特定类型的对象关联的某些属性。换句话说,给定对象的属性是每种对象类型固有地拥有的数据和能力。

也许您创建了一个类似的 python 脚本,并且像默认的 python 模块 lightgbm 一样。

尝试使用开始步骤开始开发,这对我来说效果很好,请参阅类似的错误示例:

>>> import lightgbm 
>>> from lightgbm import *

这是sintax导入的错误(bad ligtgbm):

>>> from ligtgbm import Dataset
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named ligtgbm
>>> from lightgbm import Dataset

未定义的错误:

>>> d_train=lightgbm.Dataset(train_x,label=train_y)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'train_x' is not defined
>>> train_x =''
>>> train_y =''
>>> d_train=lightgbm.Dataset(train_x,label=train_y)
>>> dir(d_train)
['_Dataset__init_from_csc', '_Dataset__init_from_csr', '_Dataset__init_from_list_np2d', '_Dataset__init_from_np2d', '__class__', '__del__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_free_handle', '_lazy_init', '_predictor', '_reverse_update_params', '_set_predictor', '_update_params', 'categorical_feature', 'construct', 'create_valid', 'data', 'feature_name', 'free_raw_data', 'get_data', 'get_field', 'get_group', 'get_init_score', 'get_label', 'get_ref_chain', 'get_weight', 'group', 'handle', 'init_score', 'label', 'need_slice', 'num_data', 'num_feature', 'pandas_categorical', 'params', 'params_back_up', 'reference', 'save_binary', 'set_categorical_feature', 'set_feature_name', 'set_field', 'set_group', 'set_init_score', 'set_label', 'set_reference', 'set_weight', 'silent', 'subset', 'used_indices', 'weight']

关于python - 属性错误: Module "lightgbm" has no attribute "LGBMClassifier" and "Dataset",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55312601/

相关文章:

python-3.x - XGBoost 最佳迭代

lightgbm - 如何正确保存mlr3 lightgbm模型?

python - 如何重命名包名称

python - MySQL 服务器已经消除了 Pylons、SQLAlchemy、Apache 的错误

python - 我的输出需要是这样的,它没有出现我需要的样子

python - Python 如何知道变量的数据类型?

python - 手动调用 __enter__ 和 __exit__

python - '属性错误: module 'usbiss' has no attribute Aclass' when creating class instance

python - 为什么 ImportError : No module named lightgbm

python - XGBoost/lightGBM 如何评估 ndcg 的排名任务?