def transform_data(x_i, le, with_fit=True):
if isinstance(le, preprocessing.MinMaxScaler) or isinstance(le, preprocessing.Binarizer):
x_i = x_i.astype(np.float)
if with_fit:
le.fit(x_i.reshape((-1, 1)))
x_i = le.transform(x_i.reshape((-1, 1)))
elif isinstance(le, preprocessing.LabelEncoder):
if with_fit:
le.fit(x_i)
x_i = le.transform(x_i.reshape((-1, 1)))
else:
raise ValueError("unknow transform")
return x_i.reshape((-1)), le
评论列表
文章目录