Skip to content

Instantly share code, notes, and snippets.

View myagmur01's full-sized avatar

myagmur myagmur01

  • New York Area
View GitHub Profile
@angeligareta
angeligareta / generate_class_weights.py
Created June 8, 2021 10:28
Method to generate class weights given a multi-class or multi-label set of classes using Python, supporting one-hot-encoded labels.
import numpy as np
from sklearn.utils.class_weight import compute_class_weight
from sklearn.preprocessing import MultiLabelBinarizer
def generate_class_weights(class_series, multi_class=True, one_hot_encoded=False):
"""
Method to generate class weights given a set of multi-class or multi-label labels, both one-hot-encoded or not.
Some examples of different formats of class_series and their outputs are: