23 lines
632 B
Python
23 lines
632 B
Python
import os
|
|
|
|
import numpy as np
|
|
from sklearn.utils import class_weight
|
|
|
|
|
|
def exists_or_make_path(p):
|
|
if not os.path.exists(p):
|
|
os.makedirs(p)
|
|
|
|
|
|
def get_custom_class_weights(client, server):
|
|
client_class_weight = class_weight.compute_class_weight('balanced', np.unique(client), client)
|
|
server_class_weight = class_weight.compute_class_weight('balanced', np.unique(server), server)
|
|
return {
|
|
"client": client_class_weight,
|
|
"server": server_class_weight
|
|
}
|
|
|
|
|
|
def get_custom_sample_weights(client, server):
|
|
return class_weight.compute_sample_weight("balanced", np.vstack((client, server)).T)
|