Search code examples
tensorflowtensorflow-estimator

Does anyone know how we can change the loss function in DNNClassifier tensorflow premade estimator?


I want to use a separate loss function in the DNNClassifier as the data is highly imbalanced i want to use tf.nn.weighted_cross_entropy_with_logits as the loss function but i guess i need to build a new estimator for it? Is it possible to change the loss function in the existing pre baked DNNClassifier by tensorflow Estimator API?


Solution

  • You can set the classifier's optimizer and the activation function in the hidden layers, but I don't think you can define a custom loss function.

    Since your input data is "highly imbalanced," you can set custom weights by assigning your weights to the constructor's weight_column argument. The documentation is here.