'Issue with training clasification Neural Network

I have converted a regression machine learning problem to a clasification one via the pd.cut() function (basically splits the regression range of the labels into bins). When trying to train the model I get various issues such as

 ValueError                                Traceback (most recent call last)
<ipython-input-93-bea8c9e6a3db> in <module>()
     18 
     19 # 3. Fit the model
---> 20 model_10.fit(X_train, y_train, epochs=200)
     21 # , validation_data=(X_test, y_test)

1 frames
/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/constant_op.py in convert_to_eager_tensor(value, ctx, dtype)
    100       dtype = dtypes.as_dtype(dtype).as_datatype_enum
    101   ctx.ensure_initialized()
--> 102   return ops.EagerTensor(value, ctx.device_name, dtype)
    103 
    104 

ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type pandas._libs.interval.Interval).

I tried converting the data to tensor format or numpy arrays, but a Graph error appeared:

In this image you can see how the labels of the model look

# Set seed
tf.random.set_seed(18)

# 1. Create model
model_10= tf.keras.Sequential([
                                      
                                      tf.keras.layers.Dense(50, activation='relu'),
                                      tf.keras.layers.Dense(25, activation='relu'), 
                                      tf.keras.layers.Dense(25, activation='relu'),
                                      tf.keras.layers.Dense(15, activation=tf.keras.activations.softmax)

])

# 2. Compile model
model_10.compile(loss=tf.keras.losses.SparseCategoricalCrossentropy(),
                 optimizer=tf.keras.optimizers.SGD(lr=0.01),
                 metrics=['accuracy'])

# 3. Fit the model
model_10.fit(X_train, y_train, epochs=200)

above is the model I tried to use, (the data was split with sklearn)

I also tried to simply round the regression values to the nearest int (5 classes in total). Nonetheless this implementation also didn't prove to work.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source