LightGBM:ValueError: DataFrame.dtypes for data must be int, float or bool.

Published on:
Last updated:

This post is also available in: Japanese

This error is about using LightGBM.
In short, LightGBM is not compatible with “Object” type with pandas DataFrame, so you need to encode to “int, float or bool” by using LabelEncoder(sklearn.preprocessing.LabelEncoder) etc…
Following is simple sample code.

ValueError: DataFrame.dtypes for data must be int, float or bool. Did not expect the data types in fields ...

fit() and transform() the pandas DataFrame object by using LabelEncoder(sklearn.preprocessing.LabelEncoder) of sklearn.

# coding:utf-8
from sklearn import preprocessing
import numpy as np
import pandas as pd
# Sample data
data = ["ABC", "123", 1, 2, "def"]
# Create pandas DataFrame Object
df = pd.DataFrame(data)
# Create LabelEncoder Object and fit(),transform()
lbl = preprocessing.LabelEncoder()
sample = lbl.transform(df)
# Converted value by LabelEncoder
print sample # This Outputs [2 3 0 1 4]
No tags for this post.

Kuniyoshi Takemoto is the founder of LLC, and editor of this blog( more and connect with me on Google+,LinkedIn(English).