def opt_2_obj_func(w, X, y, n_class):
"""
Function to be minimized in the EN_OPT_2 ensembler.
In this case there is only one weight for each classification restlt to be
combined.
Parameters:
----------
w: ndarray size=(n_preds)
Candidate solution to the optimization problem (vector of weights).
X: ndarray size=(n_samples, n_preds * n_class)
Solutions to be combined horizontally concatenated.
y: ndarray size=(n_samples,)
Class labels
n_class: int
Number of classes in the problem, i.e. = 12
"""
w = np.abs(w)
sol = np.zeros((X.shape[0], n_class))
for i in range(len(w)):
sol += X[:, i*n_class:(i+1)*n_class] * w[i]
#Minimizing the logloss
sc_ll = log_loss(y, sol)
return sc_ll
评论列表
文章目录