0

I would like to classify by LightGBM algorithm for Multiclass Multilable Classification but I encounter a problem during training because of not being a list the input. DATA is sampling rows The length of real rows is 10000

dataset = pd.read_csv('Data.csv') 
X = dataset.iloc[:,np.r_[0:6, 7:27]].values
y = dataset.iloc[:,np.r_[6]].values

x_train, x_test, y_train, y_test = train_test_split(X, y,test_size = 0.25, random_state = 0)
from sklearn.preprocessing import StandardScaler
sc=StandardScaler()
x_train = sc.fit_transform(x_train)
x_test = sc.transform(x_test)
import lightgbm as lgb
d_train = lgb.Dataset(x_train, label=y_train)
params = {}
params['learning_rate'] = 0.003
params['boosting_type'] = 'gbdt'
params['objective'] = 'binary'
params['metric'] = 'binary_logloss'
params['sub_feature'] = 0.5
params['num_leaves'] = 10
params['min_data'] = 50
params['max_depth'] = 10
clf = lgb.train(params, d_train, 100)

y_pred=clf.predict(x_test)

for i in range(0,99):
 if y_pred[i]>=.5:
    y_pred[i]=1
 else:
    y_pred[i]=0

from sklearn.metrics import confusion_matrix
cm = confusion_matrix(y_test, y_pred)

I encounter this problem:

    clf = lgb.train(params, d_train, 100)
  File "..\lightgbm\engine.py", line 228, in train
    ...
  File "..\lightgbm\basic.py", line 1336, in set_label
    label = list_to_1d_numpy(_label_from_pandas(label), name='label')
  File "..\lightgbm\basic.py", line 86, in list_to_1d_numpy
    "It should be list, numpy 1-D array or pandas Series".format(type(data).__name__, name))

This error is found in basic.py in a function: """Convert data to numpy 1-D array.""" While when I have changed my data to 1D by

y_train = np.reshape(y_train, [1,trainsize])
x_train = np.reshape(x_train, [1,trainsize*26])

The problem is not solved! Then I use ravel to make 1D for x_train, y_train

x_train = np.ravel(x_train)
y_train = np.ravel(y_train)

but new error is shown:

\lib\site-packages\lightgbm\basic.py", line 872, in __init_from_np2d raise ValueError('Input numpy.ndarray must be 2 dimensional')
ValueError: Input numpy.ndarray must be 2 dimensional

What is wrong? How I can solve this?

4
  • What are x_train and y_train shape?
    – Mehraban
    Oct 20, 2019 at 8:12
  • can you just provide us output of x_train.shape and y_train.shape?
    – Mehraban
    Oct 20, 2019 at 8:19
  • try reshaping y_train to be (7500,).
    – Mehraban
    Oct 20, 2019 at 9:05
  • \lib\site-packages\lightgbm\basic.py", line 872, in __init_from_np2d raise ValueError('Input numpy.ndarray must be 2 dimensional') ValueError: Input numpy.ndarray must be 2 dimensional Oct 20, 2019 at 9:23

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.