SteiMi / denseweight

The imbalanced regression method DenseWeight produces sample weights for data points in regression tasks so that there is a higher emphasis on ML model performance for rare (and often extreme) data points in comparison to common data points. This repository provides a Python package with which one can easily use DenseWeight.
GNU General Public License v3.0
37 stars 5 forks source link

Clarification on using DenseLoss #1

Open darpitdavetamu opened 2 years ago

darpitdavetamu commented 2 years ago

I understand the concept of DenseLoss/weights broadly. But to practically use it do I just specify the weights computed by DenseWeight in the 'loss_weight' parameter while compiling the model or is there some other way that I use it as a custom_loss function Usage: dw = DenseWeight(alpha=4.0) wts = dw.fit(y)

tf_model.compile( optimizer=tf.keras.optimizers.Adam(learning_rate=0.001),
loss = [tf.keras.losses.MeanSquaredError()], metrics=[tf.keras.metrics.MeanSquaredError()], loss_weights=wts)

SteiMi commented 2 years ago

I am not that well-versed with Keras but looking at its documentation (https://keras.io/api/models/model_training_apis/) there seems to be a sample_weight parameter in the .fit() method of the model. Providing the weights through this parameter should do what you are looking for, if I'm not mistaken.