###############################################################################
# Binner
import numpy
from nimbusml import FileDataStream
from nimbusml.datasets import get_dataset
from nimbusml.preprocessing.normalization import Binner

# data input (as a FileDataStream)
path = get_dataset('infert').as_filepath()
data = FileDataStream.read_csv(
    path,
    sep=',',
    numeric_dtype=numpy.float32)  # Error with integer input
print(data.head())
#    age  case education  induced  parity  pooled.stratum  row_num  ...
# 0  26.0   1.0    0-5yrs      1.0     6.0             3.0      1.0  ...
# 1  42.0   1.0    0-5yrs      1.0     1.0             1.0      2.0  ...
# 2  39.0   1.0    0-5yrs      2.0     6.0             4.0      3.0  ...
# 3  34.0   1.0    0-5yrs      2.0     4.0             2.0      4.0  ...
# 4  35.0   1.0   6-11yrs      1.0     3.0            32.0      5.0  ...

xf = Binner(columns={'in': 'induced', 'sp': 'spontaneous'})

# fit and transform
features = xf.fit_transform(data)

# print features
print(features.head())
#    age  case education   in  induced  parity  ... row_num   sp  ...
# 0  26.0   1.0    0-5yrs  0.5      1.0     6.0 ...     1.0  1.0  ...
# 1  42.0   1.0    0-5yrs  0.5      1.0     1.0 ...     2.0  0.0  ...
# 2  39.0   1.0    0-5yrs  1.0      2.0     6.0 ...     3.0  0.0  ...
# 3  34.0   1.0    0-5yrs  1.0      2.0     4.0 ...     4.0  0.0  ...
# 4  35.0   1.0   6-11yrs  0.5      1.0     3.0 ...     5.0  0.5  ...
