Keras ----- Custom cost function '''''''''''''''''''' To create a customized cost function for your model, do it as the code bellow shows: .. code-block:: python def myCostFunction(y_actual, y_predicted) myCost = y_actual + y_predicted #or whatever return myCost One hot encoding '''''''''''''''' In classification problems, the data for the output neurons may not have been created as a binary valued table, but as an integer category index vector. When that is the case, it is necessary to convert it to the one hot encoding. If for example you had 4 categories, a value of 1 will be mapped to [0,1,0,0], 2 to [0,0,1,0] ad so on. The code below does this for you: .. code-block:: python myOneHotVector = keras.utils.to_categorical(data_input_vector, num_classes=n)