ensemble.py 文件源码

python
阅读 36 收藏 0 点赞 0 评论 0

项目:kaggle_airbnb 作者: svegapons 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号