I'm trying to use Python 2.7 and CatBoostRegressor with Pandas but I get
UnicodeEncodeError: '
ascii
' codec can not encode characters in position 0-4: ordinal not in range (128)
I use a unicode sandwich and read csv as:
df = pd.read_csv ('out.csv', index_col = 0, encoding = 'utf8')
.
After reading the data, I perform a check:
print df.apply(lambda x: pd.lib.infer_dtype(x.values))
node integer
name unicode
region unicode
price floating
hour integer
year integer
month integer
day integer
dtype: object
Apparently, Catboost tries to make the encoding, but not successfully. How can this be avoided?
simplified code:
import pandas as pd
from catboost import CatBoostRegressor
lst2 = [100001,100002,100003,100004,100005]
lst3 = [u'Хлеб',u'Молоко',u'Чай',u'Кофеёк',u'Пончики']
lst4 = [100.0,200.1,100.0,3.5,200.0]
lst5 = [876.0,185.1023,101.12698,301.5023,200.0]
lst6 = [1,1,1,1,1]
df = pd.DataFrame({u'node' : lst2, u'name':lst3, u'vol':lst4, u'price':lst5, u'hour':lst6},
columns=[u'node', u'name', u'vol', u'price', u'hour'])
train_data = df.iloc[:-2, :]
train_labels = train_data[u'price'].values
train_data = train_data.drop([u'price'], axis = 1)
cat_features = [1]
clf = CatBoostRegressor(iterations=100, learning_rate=0.1, depth=4)
clf.fit(train_data, train_labels, cat_features)