scikit-learn/scikit-learn

PLSRegression VIP score calculation

Open

#7 050 ouverte le 19 juil. 2016

Voir sur GitHub
 (14 commentaires) (4 réactions) (0 assignés)Python (27 020 forks)batch import
Enhancementhelp wantedmodule:cross_decomposition

Métriques du dépôt

Stars
 (66 084 stars)
Métriques de merge PR
 (Merge moyen 10j) (90 PRs mergées en 30 j)

Description

I was looking for an implementation of VIP (Variable Importance in the Projection) scoring for PLS models as described in this publication.

The algorithm from that paper is implemented in this MATLAB code which is in The MATLAB code is available under a BSD License. Below is a Python implementation of this same code, which produces the VIP scores from scikit-learn PLSRegression models.

def vip(x, y, model):
    t = model.x_scores_
    w = model.x_weights_
    q = model.y_loadings_

    m, p = x.shape
    _, h = t.shape

    vips = np.zeros((p,))

    s = np.diag(t.T @ t @ q.T @ q).reshape(h, -1)
    total_s = np.sum(s)

    for i in range(p):
        weight = np.array([ (w[i,j] / np.linalg.norm(w[:,j]))**2 for j in range(h) ])
        vips[i] = np.sqrt(p*(s.T @ weight)/total_s)

    return vips

Firstly, is this something that would be considered for addition to scikit-learn, and if so, where would be a good place to add it? There was a discussion on the mailing list from 2015 about adding this, but it doesn't look like it got any further.

Guide contributeur