question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ENH: multi-output class weights

See original GitHub issue

Currently, we handle single-output class weights. Keras itself should have support for multi-output class weights, but that feature is broken (https://github.com/keras-team/keras/issues/4735) and there doesn’t seem to be any plan to fix it.

Since we have access to all of sklearn’s tools, we can relatively easily implement class_weights for multiple outputs, specifically, we can implement class weights via sample weights (Keras also supports a sample weight vector per output). In fact, sklearn implements a utility to convert class weights to sample weights, and it even supports multiple outputs, but it assumes n_outputs = y.shape[1], which isn’t generally true with Keras data. This can be remedied by taking sklearn’s compute_sample_weights function and modifying it slightly; it shouldn’t be too hard.

Do you think this is worth implementing in SciKeras @stsievert ?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
stsievertcommented, Jan 21, 2021

I forgot about that use case. I meant that in my day job, I’ve only seen single-output models. Even with that, I suspect a large majority of users only care about single-output models, and I suspect the small minority who care about multiple-output models won’t care about class weights not working.

Does that sound right to you?

That’s certainly an option, it does reduce the amount of helper code in the library.

It also reduces the number of tests. That can help speed up development (which can save hours of time) because it’s one less feature to maintain.

0reactions
adriangbcommented, Jan 21, 2021

The implementation looks pretty easy. The main problem is going to be that computing sample weights requires having the target y already split up into a list of inputs. Currently, we do this before any user-defined transformers, so this would not be possible. I think this could be resolved by #167 since the sample weights could then be yielded as a Dataset (like here).

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to apply class weight to a multi-output model?
I wansn't able to use the class_weight parameter yet, but in the mean time i've found another way to apply class weighting to...
Read more >
Class weights for multi-output classification - Stack Overflow
For fitting this model, i think i need to set the class weights, so i create these : from sklearn.preprocessing import LabelEncoder from ......
Read more >
Glossary of Common Terms and API Elements - Scikit-learn
For multioutput classification, a list of dicts is used to specify weights for each output. For example, for four-class multilabel classification weights should ......
Read more >
Calibrating Class Weights with Multi-Modal Information ... - arXiv
with a class weight enhanced by RGB-only multi-scale temporal pooling [52] and attention mechanism. However, the application of.
Read more >
12V Magnitude 300W Multi-Output Class 2 LED Driver ...
12V Magnitude 300W Multi-Output Class 2 LED Driver T300L12DC - Inspired LED - - Amazon.com. ... Item Weight, ‎9.48 pounds.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found