title: python LightGBM text classicication with Tfidf
body: <p>I'm trying to introduce LightGBM for text multiclassification.
  2 columns in pandas dataframe, where 'category' and 'contents' are set as follows.</p>
  
  <p><strong>Dataframe:</strong>  </p>
  
  <pre><code>    contents               category  
  1   this is example1...    A  
  2   this is example2...    B  
  3   this is example3...    C  
  
  *Actual data frame consists of approx 600 rows and 2 columns.
  </code></pre>
  
  <p>Hereby I'm trying to classify text into 3 categories as follows.  </p>
  
  <p><strong>Codes:</strong></p>
  
  <pre><code>import pandas as pd
  import numpy as np
  
  from nltk.corpus import stopwords
  stopwords1 = set(stopwords.words('english'))
  
  from sklearn.feature_extraction.text import CountVectorizer, TfidfTransformer, TfidfVectorizer 
  from sklearn.metrics import accuracy_score
  from sklearn.model_selection import train_test_split, cross_val_score, GridSearchCV
  
  import lightgbm as lgbm
  from lightgbm import LGBMClassifier, LGBMRegressor
  
  
  #--main code--#  
  X_train, X_test, Y_train, Y_test = train_test_split(df['contents'], df['category'], random_state = 0, test_size=0.3, shuffle=True)
  
  count_vect = CountVectorizer(ngram_range=(1,2), stop_words=stopwords1)
  X_train_counts = count_vect.fit_transform(X_train)
  
  tfidf_transformer = TfidfTransformer(use_idf=True, smooth_idf=True, norm='l2', sublinear_tf=True)
  X_train_tfidf = tfidf_transformer.fit_transform(X_train_counts)
  
  lgbm_train = lgbm.Dataset(X_train_tfidf, Y_train)
  lgbm_eval = lgbm.Dataset(count_vect.transform(X_test), Y_test, reference=lgbm_train)
  
  params = {
      'boosting_type':'gbdt',
      'objective':'multiclass',
      'learning_rate': 0.02,
      'num_class': 3,
      'early_stopping': 100,
      'num_iteration': 2000, 
      'num_leaves': 31,
      'is_enable_sparse': 'true',
      'tree_learner': 'data',
      'max_depth': 4, 
      'n_estimators': 50  
      }
  
  clf_gbm = lgbm.train(params, valid_sets=lgbm_eval)
  predicted_LGBM = clf_gbm.predict(count_vect.transform(X_test))
  
  print(accuracy_score(Y_test, predicted_LGBM))
  </code></pre>
  
  <p>Then I got an error as: </p>
  
  <pre><code>ValueError: could not convert string to float: 'b'  
  </code></pre>
  
  <p>I also convert 'category' column ['a', 'b', 'c'] to int as [0, 1, 2] but got an error as </p>
  
  <pre><code>TypeError: Expected np.float32 or np.float64, met type(int64).
  </code></pre>
  
  <p>What's wrong with my code?<br>
  Any advice / suggestions will be greatly appreciated.<br>
  Thanks in advance.</p>