Создание таблицы корреляции с переменной Target в Python - PullRequest
0 голосов
/ 30 августа 2018

Я пытаюсь создать таблицу корреляции с переменной Target, но в настоящее время я столкнулся с проблемой.

Я просто хочу, чтобы список 10 лучших переменных соответствовал моей переменной Delay_Days

Я получаю 10 лучших коррелированных переменных

Мой код

def mosthighlycorrelated(mydataframe, numtoreport):
    # find the correlations
    cormatrix = data_clean.corr()
    # set the correlations on the diagonal or lower triangle to zero,
    # so they will not be reported as the highest ones:
    cormatrix *= np.tri(*cormatrix.values.shape, k=-1).T
    # find the top n correlations
    cormatrix = cormatrix.stack()
    cormatrix = cormatrix.reindex(cormatrix.abs().sort_values(ascending=False).index).reset_index()
    # assign human-friendly names
    cormatrix.columns = ["FirstVariable", "SecondVariable", "Correlation"]
    return cormatrix.head(numtoreport)

mosthighlycorrelated(data_clean['Delay_Days'], 10)

Это не работает, как ожидалось. Как это исправить.

 **Current Ouput**
First Variable  Second Variable Correlation
A                 B              0.9
C                 G              0.85
B                 D              0.7
A                 F             0.65

    **Expected Output** 
First Variable  Second Variable Correlation
A                  B             0.9
A                  F             0.7
A                  C             0.3
A                  D             0.2
A                  E              0.1
...