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

Published on:
Last updated:

Sponsored Links

This post is also available in: Japanese

This error is about using LightGBM.
In short, LightGBM is not compatible with “Object” type with pandas, 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 ...

# coding:utf-8
from sklearn import preprocessing
import numpy as np
import pandas as pd
data = ["ABC", "あああ", 1, 2, "いいい"]
df = pd.DataFrame(data)
lbl = preprocessing.LabelEncoder()
lbl.fit(df)
sample = lbl.transform(df)
print sample # This Outputs [2 3 0 1 4]

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


Sponsored Links