-1
from lightgbm import LGBMClassifier
model = LGBMClassifier()
model.fit(X_train, y_train)

This is my code. I got this error in model.fit():

  AttributeError                            Traceback (most recent call last)
    <ipython-input-76-6b35b759d36e> in <module>
          1 from lightgbm import LGBMClassifier
          2 model = LGBMClassifier()
    ----> 3 model.fit(X_train, y_train)
          4 y_pred = model.predict_proba(X_valid)

/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'

X_train is a DataFrame and has (2500,56) shape that all the dtypes are float64.

y_train is a Series and has (2500,) shape that the dtype is int64.

It worked well in other models like Xgb and RandomForest.

OZOOOH
  • 31
  • 5

1 Answers1

1

I found what I was missing.

X_train was a DataFrame that has multi-index.

X_train.columns = X_train.columns.get_level_values(0)

This code solved the problem.

OZOOOH
  • 31
  • 5