text_plain_output_1.png
from scipy.stats import pearsonr

import pandas as pd

import seaborn as sns

def getCorr(x, y):
    corr, _ = pearsonr(x, y)
    return corr

def getSlope(df):
    return abs(df['slope'])

dftrain = pd.read_csv('../input/dont-overfit-ii/train.csv')
dftest = pd.read_csv('../input/dont-overfit-ii/test.csv')

y=sns.regplot(x='1',y='target',data=dftrain)

L=[]
for feature in range(300):
    y=sns.regplot(x=str(feature),y='target',data=dftrain)
    #L.append({'feature':feature,'slope':getslope(y.get_xlim(),y.get_ylim())})
    L.append({'feature':feature,'slope':getCorr(dftrain['target'],dftrain[str(feature)])})

L.sort(key=getSlope, reverse=True)

features_to_save = []
for iteration in range(6):
    features_to_save.append(L[iteration]['feature'])

dftrain_processed = pd.DataFrame()
for iteration in features_to_save:
    feature = dftrain[str(iteration)].values
    dftrain_processed[str(iteration)] = feature

dftrain_processed