I want to add class weights to the Random Forest model from the Random Forest Decision Trees library to take into account the minority class.
I have not found in the documentation how to do it or how to modify it in the loss function. I know that in the sklearn library it can be done easily, but I am interested in using the TensorFlow library. Thank you very much for all the suggestions.
Tensorflow Decision Forests allows users to specify a weight column in the training dataset. The entries of this column will be used as example weights. This is the only way to add class weights.
When feeding a Pandas DataFrame transformed with
tfdf.keras.pd_dataframe_to_tf_dataset()
, the weight column can be specified directly with theweights=
parameter, e.g.,When feeding a Tensorflow dataset directly, separate the weight column as a third channel in the tf.Dataset (as expected by Keras). The second channel of the tf.Dataset must always be the label column.
Full Disclosure: I'm one of the authors of Tensorflow Decision Forests.