微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

AttributeError: 'tuple' 对象在使用 LGBMClassifier 包装器时没有属性 'encode'

如何解决AttributeError: 'tuple' 对象在使用 LGBMClassifier 包装器时没有属性 'encode'

我正在尝试在 python 中使用 sklearn 包装器 LGBMClassifier 类。数据集的形状和类型:

print(type(train_x))
train_x.shape

(3125,18)

print(type(train_y))
train_y.shape

(3125,)

from lightgbm import LGBMClassifier

lgbm_wrapper = LGBMClassifier(n_estimators=400,learning_rate=0.1,random_state=123)
lgbm_wrapper.fit(train_x,train_y,verbose=True,eval_metric="logloss")

它给了我一个属性错误

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-13-74f8c97dd31f> in <module>()
      2 
      3 lgbm_wrapper = LGBMClassifier()
----> 4 lgbm_wrapper.fit(train_x,eval_metric="logloss")

8 frames
/usr/local/lib/python3.6/dist-packages/lightgbm/basic.py in c_str(string)
    110 def c_str(string):
    111     """Convert a Python string to C string."""
--> 112     return ctypes.c_char_p(string.encode('utf-8'))
    113 
    114 

AttributeError: 'tuple' object has no attribute 'encode'

这是什么意思?我在 Google colab 文档中运行它,但我应该安装其他实用程序来完成我的工作吗?

解决方法

你能分享一下 Pandas 数据框的 dtypes 吗

./node_modules/.bin/electron index.js

我感觉你的数据框中的一个特性是元组?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。